Create a gist now

Instantly share code, notes, and snippets.

#!/usr/bin/python3
import time
import json
import urllib.request
raw = urllib.request.urlopen("http://api.openweathermap.org/data/2.5/forecast?q=Pardubice").read()
js = json.loads(raw.decode("UTF-8"))
future = [x for x in js["list"] if x["dt"] > time.time()]
select = min(future, key=lambda x: x["dt"])
iid = select["weather"][0]["id"]
cls = int(iid / 100)
if cls == 2:
print("lightning")
elif cls == 3 or cls == 5:
print("rain")
elif cls == 6:
print("snow")
elif cls == 7:
print("mist")
elif cls == 8 and iid == 800:
print("clear")
elif cls == 8 and iid <= 802:
print("clear+cloud")
elif cls == 8:
print("cloudy")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment