RE: Getting Data from Personal Weather Stations
Brought to you by:
iridium
From: Jake O. <ja...@or...> - 2003-01-27 22:49:11
|
OK, just an FYI, I'm playing with this code at http://www.sunrayinc.com/sunriver/weather/index-new.php . I'll keep you posted on my success. Right now it's grabbing the entire file, but, in reality, all I need is the last line of the file (as all I'm displaying = is the most current conditions). Any idea on to do just that? I'll work on getting the station into the CSV and into the database. -Jake -----Original Message----- From: php...@li... [mailto:php...@li...] On Behalf Of = Martin Geisler Sent: Monday, January 27, 2003 1:25 PM To: php...@li... Subject: Re: Getting Data from Personal Weather Stations "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=3DKORSUN= RI1&f > ormat=3D1 > > 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?=20 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 =3D new phpweather(); $i =3D 0; $fp =3D fopen('http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=3D= KORS UNRI1&format=3D1', 'r'); while ($line =3D fgets($fp, 1024)) { if ($line !=3D "\n" && $line !=3D "<br>\n") { $data =3D explode(',', $line); if (count($data) !=3D 14 || $data[0] =3D=3D 'Time') continue; $i++; //print_r($data); $icao =3D sprintf('XX%02d', $i); =20 ereg('([0-3][0-9]) ([0-9]{2}):([0-9]{2})', $data[0], $regs); $date =3D sprintf(' %02d%02d%02dZ', $regs[1], $regs[2], $regs[3]); $temp =3D strtr(sprintf(' %02d/%02d', ($data[1]-32) * 5/9, ($data[2]-32) * 5/9), '-', 'M'); $altimeter =3D sprintf(' A%04d', $data[3]*100); $wind =3D sprintf(' %02d0%02dG%02dKT', round($data[5]/10), round($data[6] * 0.869), round($data[7] * 0.869)); if ($data[9] > 0) $precipitation =3D sprintf(' P%04d', round($data[9]*100)); else $precipitation =3D ''; $clouds =3D sprintf(' %s///', $data[10]); $conditions =3D ' ' . $data[11]; $metar =3D $icao . $date . $wind . $temp . $clouds . $conditions . $altimeter . $precipitation . "\n"; //echo $metar; $weather->set_metar($metar); $text =3D new pw_text_en($weather); //print_r($text); =20 echo '<blockquote>' . $text->print_pretty() . "</blockquote>\n"; } } ?> --=20 Martin Geisler My GnuPG Key: 0xF7F6B57B See http://gimpster.com/ and http://phpweather.net/ for: PHP Weather =3D> Shows the current weather on your webpage and PHP Shell =3D> A telnet-connection (almost :-) in a PHP page. ------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld =3D Something 2 See! http://www.vasoftware.com _______________________________________________ PHPWeather-devel mailing list PHP...@li... https://lists.sourceforge.net/lists/listinfo/phpweather-devel |