+ Reply to Thread
Results 1 to 13 of 13

Thread: How to put weather on my site?

  1. #1

    Default How to put weather on my site?

    I've been trying to put yahoo weather on my site thru a feed (rss)
    With NO luck..

    Can someone be kind enough to post step-by-step instructions using dreamweaver CS3?

    THANKS

  2. #2
    Senior Member developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi's Avatar
    Join Date
    Aug 2007
    Location
    Western Mass
    Posts
    1,070

    Default Getting Weather on your Site

    I expect ALOT of rep for this..

    Step 1
    Copy this code, and save it as weather.php

    Code:
    <?
    class RSSParser {
    
       var $insideitem = false;
       var $tag = "";
       var $title = "";
       var $description = "";
       var $link = "";
    
       function startElement($parser, $tagName, $attrs) {
           if ($this->insideitem) {
               $this->tag = $tagName;
           } elseif ($tagName == "ITEM") {
               $this->insideitem = true;
           }
       }
    
       function endElement($parser, $tagName) {
           if ($tagName == "ITEM") {           
               $title = $this->title;
               $desc = $this->description;
    
                echo "<div><strong>" . $title . "</strong></div>";
                echo "<div>" . $desc . "</div>";
               
               $this->insideitem = false;
           }
       }
    
       function characterData($parser, $data) {
           if ($this->insideitem) {
               switch ($this->tag) {
                   case "TITLE":
                   $this->title .= $data;
                   break;
                   case "DESCRIPTION":
                   $this->description .= $data;
                   break;
                   case "LINK":
                   $this->link .= $data;
                   break;
               }
           }
       }
    }
    
    $location = $_POST['location'];
    
    if(!isset($location)) {
    ?>
    <div><strong>Enter in your zipcode below</strong></div>
    <form action="weather.php" method="post">
    <div>
        Zipcode: <input type="text" name="location" size="10" /> <input type="submit" value="GO" />
    </div>
    </form>
    <? 
    }
    else {
        $url = "http://weather.yahooapis.com/forecastrss?p=" . $location;
        
        $xml_parser = xml_parser_create();
        $rss_parser = new RSSParser();
        xml_set_object($xml_parser,&$rss_parser);
        xml_set_element_handler($xml_parser, "startElement", "endElement");
        xml_set_character_data_handler($xml_parser, "characterData");
        $fp = fopen("$url","r")
           or die("Error reading RSS data.");
        while ($data = fread($fp, 4096))
           xml_parse($xml_parser, $data, feof($fp))
               or die(sprintf("XML error: %s at line %d",  
                   xml_error_string(xml_get_error_code($xml_parser)),  
                   xml_get_current_line_number($xml_parser)));
        fclose($fp); 
        
        xml_parser_free($xml_parser);
    }
    ?>
    Step 2
    Oh wait, thats it.

    This example: www.developmy.mobi/weather.php
    Last edited by developmy.mobi; 12-24-2008 at 02:19 PM.

  3. #3
    Senior Member developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi's Avatar
    Join Date
    Aug 2007
    Location
    Western Mass
    Posts
    1,070

    Default

    Only want to have a static zipcode?

    Use this code:

    Code:
    <?
    class RSSParser {
    
       var $insideitem = false;
       var $tag = "";
       var $title = "";
       var $description = "";
       var $link = "";
    
       function startElement($parser, $tagName, $attrs) {
           if ($this->insideitem) {
               $this->tag = $tagName;
           } elseif ($tagName == "ITEM") {
               $this->insideitem = true;
           }
       }
    
       function endElement($parser, $tagName) {
           if ($tagName == "ITEM") {           
               $title = $this->title;
               $desc = $this->description;
    
                echo "<div><strong>" . $title . "</strong></div>";
                echo "<div>" . $desc . "</div>";
               
               $this->insideitem = false;
           }
       }
    
       function characterData($parser, $data) {
           if ($this->insideitem) {
               switch ($this->tag) {
                   case "TITLE":
                   $this->title .= $data;
                   break;
                   case "DESCRIPTION":
                   $this->description .= $data;
                   break;
                   case "LINK":
                   $this->link .= $data;
                   break;
               }
           }
       }
    }
    
    $location = "01301";
    
        $url = "http://weather.yahooapis.com/forecastrss?p=" . $location;
        
        $xml_parser = xml_parser_create();
        $rss_parser = new RSSParser();
        xml_set_object($xml_parser,&$rss_parser);
        xml_set_element_handler($xml_parser, "startElement", "endElement");
        xml_set_character_data_handler($xml_parser, "characterData");
        $fp = fopen("$url","r")
           or die("Error reading RSS data.");
        while ($data = fread($fp, 4096))
           xml_parse($xml_parser, $data, feof($fp))
               or die(sprintf("XML error: %s at line %d",  
                   xml_error_string(xml_get_error_code($xml_parser)),  
                   xml_get_current_line_number($xml_parser)));
        fclose($fp); 
        
        xml_parser_free($xml_parser);
    ?>
    This example: www.developmy.mobi/weather2.php

  4. #4
    Senior Member developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi's Avatar
    Join Date
    Aug 2007
    Location
    Western Mass
    Posts
    1,070

    Default

    Mods, make this a sticky?

  5. #5
    Founding Member Scandiman is a .mobi legend Scandiman is a .mobi legend Scandiman is a .mobi legend Scandiman is a .mobi legend Scandiman is a .mobi legend Scandiman is a .mobi legend Scandiman is a .mobi legend Scandiman is a .mobi legend Scandiman is a .mobi legend Scandiman is a .mobi legend Scandiman's Avatar
    Join Date
    Jun 2007
    Location
    NorCal
    Posts
    8,933

    Default

    Nice stuff, rep+

    I was wondering if you have code to plug into noaa.gov or weather.gov instead of the yahoo api?

    Quote Originally Posted by developmy.mobi View Post
    Mods, make this a sticky?
    stuck!

  6. #6
    Senior Member developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi's Avatar
    Join Date
    Aug 2007
    Location
    Western Mass
    Posts
    1,070

    Default

    In the second example, just change the $url variable to :

    http://www.rss.noaa.gov/noaa-gov.xml

    for example.

    It doesn't look like they have forecasts for RSS.
    Last edited by developmy.mobi; 12-24-2008 at 03:19 PM.

  7. #7
    Senior Member Gerry is a .mobi demi-god Gerry is a .mobi demi-god Gerry is a .mobi demi-god Gerry is a .mobi demi-god Gerry is a .mobi demi-god Gerry is a .mobi demi-god Gerry is a .mobi demi-god Gerry is a .mobi demi-god Gerry is a .mobi demi-god Gerry is a .mobi demi-god Gerry is a .mobi demi-god Gerry's Avatar
    Join Date
    Jun 2007
    Location
    Living and Lovin in North Carolina, y'all.
    Posts
    5,976

    Default

    I'll rep to that!

    Cheers!




  8. #8

    Default

    RRRRRREEEEEEEEEPPPPPPEEEEEEEDDDDDDDDD!!!!!!

    Thanks Dave....

    Gonna try it out........
    Last edited by pcaero; 12-24-2008 at 06:10 PM.

  9. #9
    Senior Member noonoo1 is a .mobi knight noonoo1 is a .mobi knight noonoo1 is a .mobi knight noonoo1 is a .mobi knight noonoo1 is a .mobi knight noonoo1 is a .mobi knight noonoo1's Avatar
    Join Date
    Jul 2007
    Location
    Wales, UK
    Posts
    2,840

    Default

    will this work for the uk weather?

  10. #10

    Default

    Quote Originally Posted by developmy.mobi View Post
    Only want to have a static zipcode?

    Use this code:

    Code:
    <?
    class RSSParser {
     
       var $insideitem = false;
       var $tag = "";
       var $title = "";
       var $description = "";
       var $link = "";
     
       function startElement($parser, $tagName, $attrs) {
           if ($this->insideitem) {
               $this->tag = $tagName;
           } elseif ($tagName == "ITEM") {
               $this->insideitem = true;
           }
       }
     
       function endElement($parser, $tagName) {
           if ($tagName == "ITEM") {           
               $title = $this->title;
               $desc = $this->description;
     
                echo "<div><strong>" . $title . "</strong></div>";
                echo "<div>" . $desc . "</div>";
     
               $this->insideitem = false;
           }
       }
     
       function characterData($parser, $data) {
           if ($this->insideitem) {
               switch ($this->tag) {
                   case "TITLE":
                   $this->title .= $data;
                   break;
                   case "DESCRIPTION":
                   $this->description .= $data;
                   break;
                   case "LINK":
                   $this->link .= $data;
                   break;
               }
           }
       }
    }
     
    $location = "01301";
     
        $url = "http://weather.yahooapis.com/forecastrss?p=" . $location;
     
        $xml_parser = xml_parser_create();
        $rss_parser = new RSSParser();
        xml_set_object($xml_parser,&$rss_parser);
        xml_set_element_handler($xml_parser, "startElement", "endElement");
        xml_set_character_data_handler($xml_parser, "characterData");
        $fp = fopen("$url","r")
           or die("Error reading RSS data.");
        while ($data = fread($fp, 4096))
           xml_parse($xml_parser, $data, feof($fp))
               or die(sprintf("XML error: %s at line %d",  
                   xml_error_string(xml_get_error_code($xml_parser)),  
                   xml_get_current_line_number($xml_parser)));
        fclose($fp); 
     
        xml_parser_free($xml_parser);
    ?>
    This example: www.developmy.mobi/weather2.php


    Dave,

    Is there a way to just display the


    Current Conditions:
    Cloudy, 53 F

    and not the forcasts...

    THX

  11. #11
    Senior Member developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi is very knowledgeable in all things .mobi developmy.mobi's Avatar
    Join Date
    Aug 2007
    Location
    Western Mass
    Posts
    1,070

    Default

    Quote Originally Posted by noonoo1 View Post
    will this work for the uk weather?
    See: www.londonweather.mobi

    If you go to http://developer.yahoo.com

    And go to the weather section, they have a section that allows you to use international location codes.

    Hope this helps,
    Dave

  12. #12
    New Member Gabriel knows how to spell .mobi
    Join Date
    Dec 2007
    Posts
    17

    Default

    Hint: Just one word (or two): metar files!

    PS: Now be a good boy and do your homework... and youll gonna have weather in your site!!!

  13. #13
    Mobility Member firemax knows how to spell .mobi firemax's Avatar
    Join Date
    Jan 2010
    Location
    Colombo
    Posts
    44

    Default

    i done this with weather . com API joining with a ip2country database. users don't need to choose location manually now.

+ Reply to Thread

Similar Threads

  1. When is the Weather Channel Going to Promote Weather.mobi?
    By thinking1 in forum News & Discussion
    Replies: 14
    Last Post: 01-04-2009, 11:49 PM
  2. Replies: 16
    Last Post: 10-24-2008, 08:31 AM
  3. weather.com advertising weather.mobi
    By thebiffenator in forum News & Discussion
    Replies: 13
    Last Post: 07-09-2008, 11:01 AM
  4. Replies: 14
    Last Post: 11-13-2007, 01:35 AM
  5. Replies: 7
    Last Post: 08-15-2007, 10:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
A Yup.mobi Mobile Site
Mobile Dating