-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeekWeather.py
executable file
·87 lines (64 loc) · 2.47 KB
/
GeekWeather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/python
from forecastio import Forecastio
import datetime
import os
def main():
forecast = Forecastio("dada3cbcc93a16056f865e34daec507a")
# Get Current weather
result_current = forecast.load_forecast(40.4017,-74.0368,
time=datetime.datetime.now(),units="si")
# Process weather data
if result_current['success'] is True:
byCurrent = forecast.get_currently()
byMinute = forecast.get_minutely()
byHour = forecast.get_hourly()
byDay = forecast.get_daily()
else:
print "A problem occured communicating with the Forecast.io API"
# Print what we want, lining stuff up neatly
print "Right Now: %-10s %s" % ("", byCurrent.summary)
print "Next Hour: %-10s %s" % ("", byMinute.summary)
print "Next 24 Hours: %-6s %s" % ("", byHour.summary)
print "Next 7 Days: %-8s %s" % ("", byDay.summary)
# Get us to our script folder so the link is created in the right place
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
# Get our icon and create the link. Go my most specific weather conditions.
iconimg = "None"
if str(byCurrent.icon) == "None":
if str(byMinute.icon) == "None":
if str(byHour.icon) == "None":
iconimg = byDay.icon
else:
iconimg = byHour.icon
else:
iconimg = str(byMinute.icon)
else:
iconimg = str(byCurrent.icon)
# Unlink the current image so it can be relinked or updated
os.unlink("current.png")
if iconimg == "clear-day":
os.symlink("icons/Sun.png","current.png")
if iconimg == "clear":
os.symlink("icons/Sun.png","current.png")
if iconimg == 'clear-night':
os.symlink("icons/Moon.png","current.png")
if iconimg == "rain":
os.symlink("icons/Rain.png","current.png")
if iconimg == 'snow':
os.symlink("icons/Snow.png","current.png")
if iconimg == 'sleet':
os.symlink("icons/Sleet.png","current.png")
if iconimg == 'wind':
os.symlink("icons/Wind.png","current.png")
if iconimg == 'fog':
os.symlink("icons/Fog.png","current.png")
if iconimg == "cloudy":
os.symlink("icons/Cloud.png","current.png")
if iconimg == 'partly-cloudy-day':
os.symlink("icons/Cloud-Day.png","current.png")
if iconimg == 'partly-cloudy-night':
os.symlink("icons/Cloud-Night.png","current.png")
if __name__ == "__main__":
main()