Skip to content

Instantly share code, notes, and snippets.

@alvinwan
Created September 14, 2021 02:09
Show Gist options
  • Save alvinwan/e8cc942271f3b135d1bf090be2fbece0 to your computer and use it in GitHub Desktop.
Save alvinwan/e8cc942271f3b135d1bf090be2fbece0 to your computer and use it in GitHub Desktop.
Enhanced Weather Report

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment