Find the answer to your Linux question:
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.
  1. #1
    X16
    X16 is offline
    Just 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.

  2. #2
    Linux 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:

    PHP Code:
    $t file('http://www.weather.com/temperature/my/fav/city');
    for (
    $i 140$i <= 150$i++) print_r($t[$i]); 
    The 140 to 150 are the fictiuous places the temperature is included in. It is illustrative here only.
    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

  3. #3
    X16
    X16 is offline
    Just 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?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux 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:
    HTML Code:
    <TD><A HREF="/newscenter/stormwatch/" CLASS="genTitleLink"><B>A few severe thunderstorms central U. S.</B></A></TD>
    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.

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •