Skip to content

Instantly share code, notes, and snippets.

@atx
Created August 6, 2014 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atx/ee9d627bc15077b3ebab to your computer and use it in GitHub Desktop.
Save atx/ee9d627bc15077b3ebab to your computer and use it in GitHub Desktop.
#!/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