Results 1 to 4 of 4
Hello everyone.
I am interested in a Linux Console weather program. I would like to know if a client exists that fetches data from sites such as weather.com and allows ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-29-2006 #1Just Joined!
- Join Date
- Nov 2004
- Posts
- 10
Linux Console Weather Client
Hello everyone.
I am interested in a Linux Console weather program. I would like to know if a client exists that fetches data from sites such as weather.com and allows output to be saved.
Thanks in advance.
- 04-30-2006 #2Linux User
- Join Date
- Dec 2004
- Posts
- 323
You could always write a screen scraper in Perl or PHP and add the data to a customised database. In case the HTML has been marked up as a table, perhaps something like the following PHP snippet could work to grab the data:
The 140 to 150 are the fictiuous places the temperature is included in. It is illustrative here only.PHP Code:$t = file('http://www.weather.com/temperature/my/fav/city');
for ($i = 140; $i <= 150; $i++) print_r($t[$i]);
You will need a database wrapper to create and execute the INSERT statement and finally a cron job to relieve you of the manual effort in grabbing the data.
Hope this helps
tech
- 04-30-2006 #3Just Joined!
- Join Date
- Nov 2004
- Posts
- 10
thanks.
So basically line 140 - 150 would be the temperture data, and it basically just prints whatever is between those lines correct?
- 04-30-2006 #4Linux User
- Join Date
- Dec 2004
- Posts
- 323
Yes, after the function file() you would in this case pick up the 140th to the 150th element, so that print_r() would produce for instance:
If you strip the string above from its html-tags, using the function described here (http://www.php.net/strip_tags), you can wrap it in an INSERT statement and execute the statement.HTML Code:<TD><A HREF="/newscenter/stormwatch/" CLASS="genTitleLink"><B>A few severe thunderstorms central U. S.</B></A></TD>
The above is purely illustrative, you will find that parsing HTML pages using file() produces PHP-arrays with many hundreds of elements and it takes some trying before you obtain the element you are looking for.
Hope this helps
Tech


Reply With Quote
