Created
September 4, 2022 13:17
-
-
Save MBlore/6111e6f3711aa5dc237637a5c9114873 to your computer and use it in GitHub Desktop.
Loading the weather in Python.
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 urllib.request | |
import json | |
def loadWeather(city): | |
url = f'https://api.openweathermap.org/data/2.5/weather?q={city}&appid={your API key goes here}&units=imperial' | |
with urllib.request.urlopen(url) as response: | |
data = response.read() | |
result = json.loads(data) | |
return result | |
london_weather = loadWeather("London") | |
singapore_weather = loadWeather("Singapore") | |
print(f"The temperature in London is:", london_weather["main"]["temp"], "F") | |
print(f"The temperature in Singapore is:", singapore_weather["main"]["temp"], "F") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment