Re: Getting Data from Personal Weather Stations
Brought to you by:
iridium
From: Martin G. <gim...@gi...> - 2003-01-27 21:25:47
|
"Jake Ortman" <ja...@or...> writes: >>I think your best bet is to contact the maintainer (Steve Runner?) and >>ask him how he collects the data. Perhaps you could get access to the >>data in a comma separated file or something like that. > > Sorry I wasn't clear. WUnderground publishes the CSV file here: > http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KORSUNRI1&f > ormat=1 > > I had no intention of trying to do reg exp search crap to convert info from > a web page (man, that would be a mess and a half). > > Anyway, would I be able to hook into this? Yes, it's doable - the code below does it! I think I've managed to extract everything that can be extracted from the file... There's still some problems: the height of the clouds isn't present in the data. I've set it to '///' which is the code used at mountain stations when the cloud layer is below the station level... it comes out at 'nil meter' in the report. Also, the names of the stations is fake. You could assign names by editing stations.csv, reloading the database and carefully give the generated METAR reports the same ICAO. <?php error_reporting(E_ALL); include('php/phpweather/phpweather.php'); include('php/phpweather/output/pw_text_en.php'); $weather = new phpweather(); $i = 0; $fp = fopen('http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KORSUNRI1&format=1', 'r'); while ($line = fgets($fp, 1024)) { if ($line != "\n" && $line != "<br>\n") { $data = explode(',', $line); if (count($data) != 14 || $data[0] == 'Time') continue; $i++; //print_r($data); $icao = sprintf('XX%02d', $i); ereg('([0-3][0-9]) ([0-9]{2}):([0-9]{2})', $data[0], $regs); $date = sprintf(' %02d%02d%02dZ', $regs[1], $regs[2], $regs[3]); $temp = strtr(sprintf(' %02d/%02d', ($data[1]-32) * 5/9, ($data[2]-32) * 5/9), '-', 'M'); $altimeter = sprintf(' A%04d', $data[3]*100); $wind = sprintf(' %02d0%02dG%02dKT', round($data[5]/10), round($data[6] * 0.869), round($data[7] * 0.869)); if ($data[9] > 0) $precipitation = sprintf(' P%04d', round($data[9]*100)); else $precipitation = ''; $clouds = sprintf(' %s///', $data[10]); $conditions = ' ' . $data[11]; $metar = $icao . $date . $wind . $temp . $clouds . $conditions . $altimeter . $precipitation . "\n"; //echo $metar; $weather->set_metar($metar); $text = new pw_text_en($weather); //print_r($text); echo '<blockquote>' . $text->print_pretty() . "</blockquote>\n"; } } ?> -- Martin Geisler My GnuPG Key: 0xF7F6B57B See http://gimpster.com/ and http://phpweather.net/ for: PHP Weather => Shows the current weather on your webpage and PHP Shell => A telnet-connection (almost :-) in a PHP page. |