Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_weather(query):
- api_url="http://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid=<api key>"
- query=urllib.parse.quote(query)
- url=api_url.format(query)
- data=urllib.request.urlopen(url).read()
- parsed=json.loads(data)
- if parsed.get("weather"):
- weather={"description":parsed["weather"][0]["description"],
- "temperature":parsed["main"]["temp"],
- "city":parsed["name"]}
- return weather
- parsed=json.loads(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement