Created
January 30, 2015 08:03
-
-
Save kozmonaut/97738b18e4241b8afeb0 to your computer and use it in GitHub Desktop.
Use OpenWeatherMap API with 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 | |
import json | |
# Define url you wanna fetch | |
url = "http://api.openweathermap.org/data/2.5/find?q=London&units=metric" | |
# Fetch url | |
response = urllib.urlopen(url) | |
# Load url response to json | |
result = json.loads(response.read()) | |
# List json elements | |
print("City: %s" %result["list"][0]["name"]) | |
print("Temperature: %s C" %result["list"][0]["main"]["temp"]) | |
print("Pressure: %s hPa" %result["list"][0]["main"]["pressure"]) | |
print("Humidity: %s %%" %result["list"][0]["main"]["humidity"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment