Thread: Getting Data from Personal Weather Stations
Brought to you by:
iridium
From: Jake O. <ja...@or...> - 2003-01-12 19:04:46
|
Hello all, I've got a simple implementation of PHPWeather 2.x running here: http://www.sunrayinc.com/sunriver/weather/ Nothing fancy, just shows the current conditions (cached in a MySQL database). The problem is that the conditions are taken from the Redmond Airport (icao=3Dkrdm). The Redmond Airport is the nearest NWS station, but it's = nearly 40 miles from here and not always entirely accurate.=20 I recently found out that the local public works department has a = weather station (http://www.sunriverowners.org/05_departments/public_works/pw_frame.html)= that's also available on Weather Underground: http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=3DKORSUN= RI1 . Would there be an easy way to pull that data to use on my site? Thanks for your help, folks! :-) -Jake | Jake Ortman - Technology Director | ja...@su... http://www.sunrayinc.com | (800) 531-1130 Fax: (541) 593-6652 | -------------------------------------- | Sunray Vacation Rentals: A Different | Kind of Vacation Rental Company=20 |
From: Martin G. <gim...@gi...> - 2003-01-16 11:47:24
|
"Jake Ortman" <ja...@or...> writes: Hi Jake > I've got a simple implementation of PHPWeather 2.x running here: > http://www.sunrayinc.com/sunriver/weather/ > > Nothing fancy, just shows the current conditions (cached in a MySQL > database). Good. > I recently found out that the local public works department has a > weather station > http://www.sunriverowners.org/05_departments/public_works/pw_frame.html) > that's also available on Weather Underground: > http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KORSUNRI1. > Would there be an easy way to pull that data to use on my site? Not with PhpWeather... PhpWeather knows how to parse a METAR report, but you're trying to parse a webpage :-) You could try to extract the information from the website with the help of regular expressions, but it would be a mess, and you would violate the copyright of the page too. 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. -- 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. |
From: Jake O. <ja...@or...> - 2003-01-16 18:10:40
|
>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 I still plan on contacting Steve, I just wanted to know how easy it is = for a joe-blow like me to hook into this data. -Jake |
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. |
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 |