-
Notifications
You must be signed in to change notification settings - Fork 1
/
darkpi.py
72 lines (59 loc) · 1.6 KB
/
darkpi.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
from blinkt import set_pixel, set_clear_on_exit, show, clear
import forecastio
import os
# API details
api_key = os.environ['DARKSKY_API']
lat = float(os.environ['LAT'])
lng = float(os.environ['LON'])
# Colours
off = [0,0,0]
blue = [29, 90, 254]
pink = [255, 0, 30]
red = [255, 0, 0]
yellow = [255, 120, 0]
orange = [255, 40, 0]
dark_blue = [0, 0, 60]
white = [255, 255, 255]
grey = [20, 20, 20]
green = [0, 255, 20]
set_clear_on_exit(False)
clear()
def display_weather(pixel, colour, brightness):
print(pixel, colour, brightness)
set_pixel(pixel, colour[0], colour[1], colour[2], brightness)
forecast = forecastio.load_forecast(api_key, lat, lng)
daily = forecast.daily()
sunrise = daily.data[0].sunriseTime
sunset = daily.data[0].sunsetTime
hourly = forecast.hourly()
for i in range(0, 8):
hourlyData = hourly.data[i]
print(i, hourlyData.icon)
brightness = 0.05
if ((hourlyData.time > sunrise) and (hourlyData.time < sunset)):
brightness = 0.5
colour = off
if hourlyData.icon == "wind":
colour = orange
elif hourlyData.icon == "rain":
colour = dark_blue
elif hourlyData.icon == "snow":
colour = white
elif hourlyData.icon == "sleet":
colour = white
elif hourlyData.icon == "fog":
colour = green
elif hourlyData.icon == "cloudy":
colour = pink
elif hourlyData.icon == "clear-day":
colour = yellow
elif hourlyData.icon == "partly-cloudy-day":
colour = orange
elif hourlyData.icon == "clear-night":
colour = yellow
elif hourlyData.icon == "partly-cloudy-night":
colour = orange
else:
colour = off
display_weather(i, colour, brightness)
show()