Skip to content

Instantly share code, notes, and snippets.

@StickmanNinja
Created September 2, 2018 06:34
Show Gist options
  • Save StickmanNinja/fc438061478df89ed3a5e17b29a72609 to your computer and use it in GitHub Desktop.
Save StickmanNinja/fc438061478df89ed3a5e17b29a72609 to your computer and use it in GitHub Desktop.
Gets weather forecast from national weather service.
import urllib2
import urllib
from bs4 import BeautifulSoup
def currentWeather(zipcode):
url = 'https://forecast.weather.gov/zipcity.php'
data = urllib.urlencode({'inputstring': str(zipcode)})
req = urllib2.Request(url=url, data=data)
resp = urllib2.urlopen(req)
content = resp.read()
soup = BeautifulSoup(content, "lxml")
forcast = soup.find(id="current_conditions-summary")
for item in forcast.find_all("p"):
print item.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment