Commit 64ab234b by source_reader

updated http client

parent dd7cd711
Showing with 19 additions and 6 deletions
import json
import requests import requests
API_KEY = "--REDACTED--" city = "Annapolis"
city_name = "Annapolis" api_key = "--REDACTED--"
URL = "https://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s&units=imperial" % (city_name, API_KEY) units = "imperial"
r = requests.get(URL)
# URL Components
scheme = "https"
host = "api.openweathermap.org"
resource = "/data/2.5/weather"
query = "q=%s&appid=%s&units=%s" % (city, api_key, units)
# Put it all together
url = scheme+"://"+host+resource+"?"+query
print(url)
# Request library handles the *whole* protocol stack :)
r = requests.get(url)
data = r.json() data = r.json()
print("It is currently %d degrees in %s" % (data['main']['temp'], city_name))
# Show some interesting weather data
print("It is currently %d degrees in %s" % (data['main']['temp'], city))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment