Created
September 2, 2018 06:34
-
-
Save StickmanNinja/fc438061478df89ed3a5e17b29a72609 to your computer and use it in GitHub Desktop.
Gets weather forecast from national weather service.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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