how to get current weather information to my program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • EngineerGirl
    New Member
    • Dec 2014
    • 2

    how to get current weather information to my program

    Hi all! I am new to python so what I am asking might be ambitious, but I want to know if there is a way to take information from the national weather service an use it as ambient tempertures to calculate heat trabsfer problems? Any help is greatly apperciated!
  • RachelCook
    New Member
    • Dec 2014
    • 3

    #2
    There are lots of many websites now that providing a weather information. But one of the best source for that is http://weather.weatherbug.com/ you can visit that site to find what you need.

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      The website source can be read with the urllib module and parsed with Beautifulsoup or other suitable HTML parser.

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        Using the url suggested by RachelCook and a specific locale, the following will extract the high and low temperatures.
        Code:
        >>> from urllib import urlopen
        >>> from bs4 import BeautifulSoup
        >>> url = "http://weather.weatherbug.com/MN/Wahkon-weather.html?zcode=z6286&zip=56386"
        >>> soup = BeautifulSoup(urlopen(url).read())
        >>> soup.find(name="span", id="divHi").get_text()
        u'33\xb0F'
        >>> soup.find(name="span", id="divLo").get_text()
        u'28\xb0F'
        >>>

        Comment

        • EngineerGirl
          New Member
          • Dec 2014
          • 2

          #5
          Thank you! That worked perfectly!

          Comment

          Working...