Created
July 24, 2015 18:25
-
-
Save isouzasoares/1f38cf319ed38b36eb1b to your computer and use it in GitHub Desktop.
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 | |
def getRSS(): | |
""" | |
Retorna o forecast do google para BSB | |
{'low':15, | |
'high':26, | |
'cond':'Possibilidade de tempestade', | |
'ico':'/ig/images/weather/chance_of_storm.gif'} | |
""" | |
try: | |
resp = urllib.urlopen("http://api.worldweatheronline.com/free/v1/weather.ashx?q=-15.96,-48.16&format=json&fx=no&key=hnenhu3wqcjepyuuz6nt6979") | |
dado = json.loads(resp.read()) | |
data = dado['data'] | |
prev = data["current_condition"][0] | |
low = int(prev["temp_C"])-2 | |
high = int(prev["temp_C"])+1 #prev.getElementsByTagName("high")[0].getAttribute("data") | |
cond = (prev["weatherDesc"][0]["value"]).encode("latin1") | |
ico = (prev["weatherIconUrl"][0]["value"]).encode("latin1") | |
fcast = {"low":low, "high":high, "cond":cond, "ico":ico} | |
except: | |
resp = urllib.urlopen("http://api.openweathermap.org/data/2.5/weather?q=brasilia,BR&lang=pt&units=metric&") | |
dado = json.loads(resp.read()) | |
prev = "" | |
low = dado["main"]["temp_min"] | |
high = dado["main"]["temp_max"] | |
cond = dado["weather"][0]["description"].encode("latin1") | |
ico = 'http://openweathermap.org/img/w/' + dado["weather"][0]["icon"].encode("latin1") + '.png' | |
fcast = {"low":low, "high":high, "cond":cond, "ico":ico} | |
return fcast | |
return getRSS() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment