Running the above report.py
gets us the temperature for any city.
> python report.py
City: Oakland
State: California
Country: United States
+73°F
from urllib.request import urlopen | |
def get_temp(city,state,country): | |
"""Reports temperature for a city, more precisely | |
@author: Lihr | |
@url: https://www.skillshare.com/classes/Coding-101-Python-for-Beginners/973997848/classroom/announcements/287595 | |
""" | |
url = "https://wttr.in/"+city+"-"+state+"-"+country+"?format=%t" | |
page = urlopen(url) | |
raw = page.read() | |
temp = raw.decode("utf-8") | |
return temp | |
city = input("City: ") | |
state = input("State: ") | |
country = input("Country: ") | |
temp = get_temp(city,state,country) | |
print(temp) |