Skip to content

Instantly share code, notes, and snippets.

@licensed
Created January 2, 2016 03:36
Show Gist options
  • Save licensed/fb5d4cfbd1e9cfddb5ef to your computer and use it in GitHub Desktop.
Save licensed/fb5d4cfbd1e9cfddb5ef to your computer and use it in GitHub Desktop.
from json import loads
from urllib.request import urlopen
from urllib.parse import quote_plus
weather_key = "" #GET YOUR KEY AT OPENWEATHERMAP.ORG
def clima_tempo(city):
url = "http://api.openweathermap.org/data/2.5/weather?q=" + quote_plus(city) + "&lang=pt&units=metric&APPID=" + weather_key
html = urlopen(url).read().decode('utf-8')
weather = loads(html)
return weather
#Usage
t = clima_tempo("Maceió")
print( "Tempo em {name}\nTemperatura: {main[temp]}°C\nTemp Min: {main[temp_min]}°C\nTemp Max: {main[temp_max]}°C\nUmidade: {main[humidity]}%".format(**t) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment