Need help with writting a javascript that displays my current weather conditions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JayCally
    New Member
    • Apr 2007
    • 1

    Need help with writting a javascript that displays my current weather conditions

    I want to add the current weather conditions in my area to my site. I've looked at some of the sites that will give you a generated script to add to your site but I don't like the way they look. I want to create my own using DIVs to house the info and javascripts to get the info and place it in those DIVs.

    I've already created the DIVs and now need a javascript to fetch/place the current conditions from my area. I have a DIV for hi/location/lo, Current Temp, image. I'm real new to javascripting and have no idea of were to start. I like how th dashboard weather widget works and took a look at the javascript file to see how that was done but got lost.

    Could anyone help? How to start?

    Any help would be great.

    Thanks
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by JayCally
    I want to add the current weather conditions in my area to my site. I've looked at some of the sites that will give you a generated script to add to your site but I don't like the way they look. I want to create my own using DIVs to house the info and javascripts to get the info and place it in those DIVs.

    I've already created the DIVs and now need a javascript to fetch/place the current conditions from my area. I have a DIV for hi/location/lo, Current Temp, image. I'm real new to javascripting and have no idea of were to start. I like how th dashboard weather widget works and took a look at the javascript file to see how that was done but got lost.

    Could anyone help? How to start?

    Any help would be great.

    Thanks
    Where are you getting the weather conditions from? How do you want to display them?

    Comment

    • rogerpride
      New Member
      • Mar 2007
      • 7

      #3
      The national weather service offers current conditions in either XML or RSS. Here's the link.

      http://www.weather.gov/data/current_obs/

      I use the php curl() function to write the XML file to my web server and then parse it with javascript.

      Try something like this:

      function get_weather() {


      $ch = curl_init();

      curl_setopt($ch , CURLOPT_URL, "XML URL");
      curl_setopt($ch , CURLOPT_HEADER, 0);
      curl_setopt($ch , CURLOPT_RETURNT RANSFER, true);

      $xml_content = curl_exec($ch);
      $fp = fopen("weather. xml", "w+");
      fwrite($fp, $xml_content);
      fclose($fp);

      curl_close($ch) ;
      }


      Call this function in your script and it will write the XML doc to weather.xml in the root folder of your web server.

      I've found that you must save it to your web server first, as javascript doesn't work well with files from a 3rd party as a security meassure. Make a recursive setTimeout() function to call it up again about once an hour to get updates.

      Comment

      Working...