A aviation & planes forum. AviationBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » AviationBanter forum » rec.aviation newsgroups » Piloting
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

how can you get live METAR data ?



 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old October 15th 04, 02:29 AM
Brenor Brophy
external usenet poster
 
Posts: n/a
Default

You can use PHP (yet another web programming language) to do this trick.
Checkout my home page at http://www.brenorbrophy.com/ to see the results. I
retrieve the METARs for some of my local airports, the airport name gets
color coded depending on the conditions (LIFR/IFR/MVFR & VFR), the time get
color'd red if its more than 1 hour old. I also get the TAF for a couple of
local airports. I use this to get a real quick over view of the local area
weather.

For the non-programmer, PHP is a scripting language that runs on a web
server. When somebody views the web-page the script is executed and it
outputs HTML code which is displayed on the web-page. Whoever is hosting
your web-page needs to allow PHP scripts to run. Now I'm not a PHP genius, I
hacked a piece of code called PHP Weather (version 2.1) which is available
at http://phpweather.sourceforge.net/.

Quick overview of what I did.

1) Downloaded and unziped PHP Weather. Put it in a directory on my web page
called weather.
2) Created a file called wx.php (my hack) and put it in same directory
3) Added an inline frame to my homepage as set wx.php as the source, the
HTML for this is:

iframe src="weather/wx.php" name="wx bar" width="600" marginwidth="0"
height="170" marginheight="0" align="middle" scrolling="no"
frameborder="0"/iframe

Here is wx.php file - it should be obivious how to modify it for a different
set of METARs and TAFs (Hint look at the arrays called $Airport & $tAirport)

html
head
titleUntitled Document/title
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/head

body
table width="596" border="0" cellpadding="1" cellspacing="0"
bordercolor="#CCCCCC" bgcolor="#FFFFFF"
tr
td width="60%" valign="top"
?php
//error_reporting(E_ALL);

/* We need the GET variables: */
extract($HTTP_GET_VARS);

/* Load PHP Weather */
require('../weather/phpweather.php');

if (empty($language)) $language = 'en';

$weather = new phpweather();
//$weather-properties['verbosity'] = 5;

$language = 'en';
require(PHPWEATHER_BASE_DIR . "/output/pw_text_$language.php");
$type = 'pw_text_' . $language;
require(PHPWEATHER_BASE_DIR . "/output/pw_images.php");
$icons = new pw_images($weather);
/*
** Airports array holds list of airports for METAR retrival
** tAirports array holds list of airports for TAF retrival
*/
$Airport = array ("KRHV","KWVI","KMRY","KAPC","KSCK","KSAC"); // For METAR
$tAirport = array ("KSJC","KMRY"); // For TAF

echo 'table width="100%" border="0" cellpadding="1" cellspacing="1"';
echo 'trtd colspan="2" valign="top" bgcolor="#99CCFF"font
face="Verdana, Arial, Helvetica, sans-serif" size="2"strongMETAR
'.gmdate("dHi\Z")."/strong/font/td/tr\n";
foreach ($Airport as $icao) {
$weather-set_icao($icao); // Set the airport code
$metar = $weather-get_metar(); // Get the METAR report
if($metar!='') { // If I've got a valid METAR then
$parts = explode(' ', $metar); // Break into parts so we can color
various bits
$num_parts = count($parts); // Count the parts
$time = $parts[1]; // Extract the time issued part
$vis = $parts[3]; // Extract visibility
$weather-decode_metar(); // Decode it so we can check visability &
ceiling
/*
** Check for flight conditions
** LIFR (Low IFR) is vis 1SM &|| ceiling 500' - Color ICAO purple
** IFR is 1SM vis 3SM &|| 500' ceiling 1000' - Color ICAO red
** MVFR (Marginal VFR) is 3SM vis 5SM &|| 1000' ceiling 3000' -
Color ICAO blue
** VFR is vis 5SM & ceiling 3000' - Color ICAO green
**
** Ceiling is altitude of lowest cloud type of BKN or OVC
*/
$vis = $weather-decoded_metar['visibility'][0]['miles']; // Get
visibility
$layer = $weather-decoded_metar['clouds']; // Get the cloud layers
$ceiling = 999999; // Init ceiling value
$group_num = 0; // Init cloud group value (there could be up to 3
cloud groups)
foreach ($layer as $key=$group) { // For each cloud group
/*
** We only care about OVC or BKN layers
*/
if (($group['condition'] == 'OVC') || ($group['condition'] == 'BKN') ||
($group['condition'] == 'VV')) {
if ($ceiling $group['ft']) { // Look for the lowest ceiling
$ceiling = $group['ft']; // Records it if lower
$group_num = $key; // Record the cloud group it occurs in
} // end of found a lower ceiling
} // end of condition OVC || BKN || VV
} // end of checking all cloud layers
if (($vis = 1) || ($ceiling = 500)) {
$flight_condition = 'LIFR';
($vis = 1) ? $vis_flag = true : $vis_flag = false;
($ceiling = 500) ? $ceiling_flag = true : $ceiling_flag = false;
}
elseif (($vis = 3) || ($ceiling = 1000)) {
$flight_condition = 'IFR';
($vis = 3) ? $vis_flag = true : $vis_flag = false;
($ceiling = 1000) ? $ceiling_flag = true : $ceiling_flag = false;
}
elseif (($vis = 5) || ($ceiling = 3000)) {
$flight_condition = 'MVFR';
($vis = 5) ? $vis_flag = true : $vis_flag = false;
($ceiling = 3000) ? $ceiling_flag = true : $ceiling_flag = false;
}
else {
$flight_condition = 'VFR';
$vis_flag = false;
$ceiling_flag = false;
}
echo 'trtd valign="top"font face="Verdana, Arial, Helvetica,
sans-serif" size="1" ';
switch ($flight_condition)
{
case 'LIFR': $color="#FF00FF"; break; // Purple color
case 'IFR' : $color="#FF0000"; break; // Red color
case 'MVFR': $color="#0000FF"; break; // Blue color
case 'VFR' : $color="#009900"; break; // Green color
default : $color="#000000"; // Should never happen but in case
leave it black color
}
echo 'color="'.$color.'"strong'.$icao."/strong/font/td\n"; //
print the airport code and close the cell
/*
** Now we want to alert the user if the METAR data is old. So we will color
the time stamp red if
** its is more than 1 hour old.
*/
echo 'td valign="top"font face="Verdana, Arial, Helvetica,
sans-serif" size="1" '; // Start the cell and set the font
if ($weather-metar_time time()-3600) { // METAR is more then 1
hour old
echo 'color="#FF0000"';
} else { // METAR is less than 1 hour old
echo 'color="#000000"';
} // end of METAR time check
echo $time.'/font';
/*
** print remainder of the METAR
**
** Plan to add color high-light of Vis or cloud causing !VFR flight
conditiond
*/
echo 'font face="Verdana, Arial, Helvetica, sans-serif"
size="1"'.substr($metar,12,strlen($metar))."/td/tr\n";
} // end of valid METAR
} // end of FOREACH loop on array of airports

echo "/table/fontbr\n";
?
/td
td width="40%" valign="top"
?php
$text = new $type($weather);
foreach ($tAirport as $icao) {
$text-weather-set_icao($icao); // Set the Airport code
$taf = $text-weather-decode_taf(); // Get and decode the TAF
if($taf['taf']!='') { // If I've got a valid TAF then
$parts = explode(' ', $taf['taf']); // Break into parts so we can
color various bits
$num_parts = count($parts); // Count the parts
$time = $parts[1]; // Extract the time issued part

echo 'table width="100%" border="0" cellpadding="1"
cellspacing="1"';
echo 'trtd valign="top" bgcolor="#99CCFF"font face="Verdana,
Arial, Helvetica, sans-serif" size="2"strongTAF '.$icao."
".$time."/strong/font/td/tr\n";
echo 'trtd valign="top"font face="Verdana, Arial, Helvetica,
sans-serif" size="1"';
while(list($i,$period) = each($taf['periods2'])) {
echo $period['data']."br\n";
} // end of while list of TAF periods
echo "/td/tr\n";
echo "/table";
} // end of valid TAF
} // end of FOREACH loop on array of airports

?
/td
/tr
/table
/body
/html


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how can you get live METAR data ? - long Bob Fry General Aviation 4 November 5th 04 06:19 AM
Pirep: Garmin GPSMAP 296 versus 295. (very long) Jon Woellhaf Piloting 12 September 4th 04 11:55 PM
No METAR Data at AOPA and NWS? Scott Lowrey Piloting 4 March 3rd 04 07:19 PM
Aviation Insurance History, data, records? cloudclimbr General Aviation 0 February 17th 04 03:36 AM
Air Force conducts live test of MOAB Otis Willie Military Aviation 0 November 21st 03 10:45 PM


All times are GMT +1. The time now is 09:32 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 AviationBanter.
The comments are property of their posters.