Embedded METAR and TAF

MarkL

Pre-Flight
Joined
Nov 26, 2007
Messages
90
Location
Nebraska
Display Name

Display name:
MarkL
Any hacks know where I can get raw Area Forecast, METAR, and TAF data for putting on a webpage?

I have a plan to extract it from the web coded output obtained at http://adds.aviationweather.gov/tafs/ but why reinvent the wheel if it's already been done.
 
If you don't want to reinvent the wheel: http://phpweather.sourceforge.net/ does what you want. It has a lot of stuff where it attempts to translate the metars..but you can get the raw data from it.
 
If you don't want to reinvent the wheel: http://phpweather.sourceforge.net/ does what you want. It has a lot of stuff where it attempts to translate the metars..but you can get the raw data from it.

Last release "June 16, 2004"? I bet it'll do the job though...or at least give you one hell of a head start.
 
I'll test it out tonight. All 3 suggestions. Thanks.
 
I'll test it out tonight. All 3 suggestions. Thanks.

Mark,

I did this once before for Grant. See the following:
http://www.pilotsofamerica.com/forum/showthread.php?t=18479&highlight=metar+php

This is the code:

Code:
<?php
function get_metar($station, &$wxInfo) {
        $fileName = "http://weather.noaa.gov/pub/data/observations/metar/stations/$station.TXT";
        $metar = '';
        $fileData = @file($fileName);  // or die('Data not available');
        if ($fileData != false) {
                list($i, $date) = each($fileData);
                $utc = strtotime(trim($date));
                set_time_data($utc,$wxInfo);
                while (list($i, $line) = each($fileData)) {
                        $metar .= ' ' . trim($line);
                        }
                $metar = trim(str_replace('  ', ' ', $metar));
                }
        return $metar;
        }


function set_time_data($utc, &$wxInfo) {
        $timeZoneOffset = date('Z');
        $local = $utc + $timeZoneOffset;
        $wxInfo['OBSERVED'] = date('D M j, H:i T',$local);
        $now = time();
        $wxInfo['NOW'] = date('D M j, H:i T',$now);
        $timeDiff = floor(($now - $local) / 60);
        if ($timeDiff < 91) $wxInfo['AGE'] = "$timeDiff min ago";
        else {
                $min = $timeDiff % 60;
                if ($min < 10) $min = '0' . $min;
                $wxInfo['AGE'] = floor($timeDiff / 60) . ":$min hr ago";
                }
        }

header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Expires: Sat,1 Jan 2000 00:00:01 GMT');

$station = $_GET['id'];
$station = strtoupper($station);
$wxInfo['STATION'] = $station;
$metar = get_metar($station,$wxInfo);


echo "$metar";

?>
Just pass the station identifier in the URL like this: metar.php?id=KLNK
 
Back
Top