Created
August 6, 2014 07:36
-
-
Save atx/ee9d627bc15077b3ebab to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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