Skip to content

Instantly share code, notes, and snippets.

@kozmonaut
Created January 30, 2015 08:03
Show Gist options
  • Save kozmonaut/97738b18e4241b8afeb0 to your computer and use it in GitHub Desktop.
Save kozmonaut/97738b18e4241b8afeb0 to your computer and use it in GitHub Desktop.
Use OpenWeatherMap API with Python
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