-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
186 lines (145 loc) · 7.49 KB
/
main.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# WEATHER DISPLAY - Bartosz Jaskulski
#
#
# --- PLEASE READ ---
# This script is for Pimoroni Inky *wHAT* Displays ONLY
# Please use impression-main.py if you have an Inky Impression
# --- PLEASE READ ---
#
#
import os, sys
from datetime import datetime, timedelta
import cond_icons
import configparser
#config.ini file
configObj = configparser.ConfigParser()
configObj.read("/home/pi/weather-report/configfile.ini")
OWMAPI = configObj["OWM_API"]
UserLoc = configObj["Location"]
api = OWMAPI["api"]
lat =float(UserLoc["latitude"])
lon = float(UserLoc["longitude"])
city = str(UserLoc["city"])
country = str(UserLoc["country"])
#Inky Libraries
from inky import InkyWHAT
from PIL import Image, ImageFont, ImageDraw
# pyOWM Libraries
from pyowm.owm import OWM
from pyowm.utils import config
from pyowm.utils import timestamps
CURR_DIR = os.path.dirname(os.path.realpath(__file__)) + "/"
RESOURCES = CURR_DIR + "resources/"
# Fonts
PIXEL_FONT = RESOURCES + "fonts/Pixel12x10.ttf"
Terminal_FONT = RESOURCES + "fonts/terminal-grotesque.ttf"
Mister_Pixel_FONT = RESOURCES + "fonts/Mister_Pixel_Regular.otf"
B_FONT = RESOURCES + "fonts/04B_03.ttf"
VG5000_FONT = RESOURCES + "fonts/VG5000-Regular.otf"
FT88Reg_FONT = RESOURCES + "fonts/FT88-Regular.otf"
TimeDate = datetime.now()
TwoHrsTime = (datetime.now()+timedelta(hours=2)).strftime("%H:00")
FourHrsTime = (datetime.now()+timedelta(hours=4)).strftime("%H:00")
SixHrsTime = (datetime.now()+timedelta(hours=6)).strftime("%H:00")
EightHrsTime = (datetime.now()+timedelta(hours=8)).strftime("%H:00")
degreeSign = u"\N{DEGREE SIGN}"
#OpenWeatherMap Integration
owm = OWM(api)
mgr = owm.weather_manager()
weather = mgr.weather_at_place(city+","+country).weather
one_call = mgr.one_call(lat, lon)
getTemp = weather.temperature("fahrenheit") #enables temp in fahrenheit
curTemp = int(getTemp["temp"]) #get current temp
#Current "feels like" Temperature
feelsLike = int(getTemp["feels_like"])
currentFeelsLike = "Feels: "+str(feelsLike)+degreeSign
#current max and min temps
maxTemp = int(getTemp["temp_max"])
minTemp = int(getTemp["temp_min"])
#Current wind speeds
getWind = weather.wind(unit="miles_hour")
curWind = int(getWind["speed"])
inky_display = InkyWHAT("yellow")
inky_display.set_border(inky_display.WHITE)
Location_ICON = RESOURCES + "icons/location.png"
LocationIcon = Image.open(Location_ICON)
img = Image.open("/home/pi/weather-report/resources/background/weather-report-bg.png")
draw = ImageDraw.Draw(img)
font_tiny = ImageFont.truetype(FT88Reg_FONT, 12)
font_small = ImageFont.truetype(FT88Reg_FONT, 12)
font_medium = ImageFont.truetype(VG5000_FONT, 32)
font_medium2 = ImageFont.truetype(FT88Reg_FONT, 18)
font_big = ImageFont.truetype(VG5000_FONT, 70)
font2 = ImageFont.truetype(VG5000_FONT, 10)
currentTemp = str(curTemp)+degreeSign
currentMaxTemp = "Max: "+str(maxTemp)+degreeSign #current temp max
currentMinTemp = "Min: "+str(minTemp)+degreeSign #current temp min
TwoHrTemp = str(int(one_call.forecast_hourly[2].temperature("fahrenheit").get("temp", 0))) #get temp in 2 hrs
TwoHrCond = str(one_call.forecast_hourly[2].status)
FourHrTemp = str(int(one_call.forecast_hourly[4].temperature("fahrenheit").get("temp", 0))) #get temp in 4 hrs
FourHrCond = str(one_call.forecast_hourly[4].status)
SixHrTemp = str(int(one_call.forecast_hourly[6].temperature("fahrenheit").get("temp", 0))) #get temp in 6 hrs
SixHrCond = str(one_call.forecast_hourly[6].status)
EightHrTemp = str(int(one_call.forecast_hourly[8].temperature("fahrenheit").get("temp", 0))) #get temp in 8 hrs
EightHrCond = str(one_call.forecast_hourly[8].status)
currentCond = str(weather.status)
currentDetailCond = str(weather.detailed_status).title()
currentHumidity = "Hum:"+str(one_call.current.humidity)+"%"
currentWind = "Wind:"+str(curWind)+" MPH"
currentLoc = ": " + city
#proper text placement
projectName = "WEATHER REPORT"
w_name, h_name = font2.getsize(projectName)
x_name = 200 - (w_name/2)
w_TwoHrTemp, h_TwoHrTemp = font_medium.getsize(TwoHrTemp)
x_TwoHrTemp = (50) - (w_TwoHrTemp/2)
w_TwoHrsTime, h_TwoHrsTime = font_tiny.getsize(TwoHrsTime)
x_TwoHrsTime = 50 - (w_TwoHrsTime/2)
w_TwoHrCond, h_TwoHrCond = font_tiny.getsize(TwoHrCond)
x_TwoHrCond = 50 - (w_TwoHrCond/2)
w_FourHrTemp, h_FourHrTemp = font_medium.getsize(FourHrTemp)
x_FourHrTemp = (150) - (w_FourHrTemp/2)
w_FourHrsTime, h_FourHrsTime = font_tiny.getsize(FourHrsTime)
x_FourHrsTime = 150 - (w_FourHrsTime/2)
w_FourHrCond, h_FourHrCond = font_tiny.getsize(FourHrCond)
x_FourHrCond = 150 - (w_FourHrCond/2)
w_SixHrTemp, h_SixHrTemp = font_medium.getsize(SixHrTemp)
x_SixHrTemp = (250) - (w_SixHrTemp/2)
w_SixHrsTime, h_SixHrsTime = font_tiny.getsize(SixHrsTime)
x_SixHrsTime = 250 - (w_SixHrsTime/2)
w_SixHrCond, h_SixHrCond = font_tiny.getsize(SixHrCond)
x_SixHrCond = 250 - (w_SixHrCond/2)
w_EightHrTemp, h_EightHrTemp = font_medium.getsize(EightHrTemp)
x_EightHrTemp = (350) - (w_EightHrTemp/2)
w_EightHrsTime, h_EightHrsTime = font_tiny.getsize(EightHrsTime)
x_EightHrsTime = 350 - (w_EightHrsTime/2)
w_EightHrCond, h_EightHrCond = font_tiny.getsize(EightHrCond)
x_EightHrCond = 350 - (w_EightHrCond/2)
#draw data and text onto display
draw.text((5, 4),TimeDate.strftime("%m-%d-%Y"), inky_display.WHITE, font2) #Time
draw.text((368, 4),TimeDate.strftime("%H:%M"), inky_display.WHITE, font2) #Date
draw.text((x_name, 4),projectName, inky_display.WHITE, font2) #project name
draw.text((155, 65), currentTemp, inky_display.BLACK, font_big) #Current temp
draw.text((292, 100), currentMaxTemp, inky_display.BLACK, font_small) #Current max temp
draw.text((292, 116), currentMinTemp, inky_display.BLACK, font_small) #Current min temp
draw.text((292, 70), currentFeelsLike, inky_display.BLACK, font_small)
#img.paste(LocationIcon, (15, 198))
#draw.text((35, 200), currentLoc, inky_display.BLACK, font_medium2) #Current location
draw.text((x_TwoHrTemp, 246), TwoHrTemp+degreeSign, inky_display.BLACK, font_medium) #Temp in 2 hrs
draw.text((x_FourHrTemp, 246),FourHrTemp+degreeSign, inky_display.BLACK, font_medium) #Temp in 4 hrs
draw.text((x_SixHrTemp, 246), SixHrTemp+degreeSign, inky_display.BLACK, font_medium) #Temp in 6 hrs
draw.text((x_EightHrTemp, 246), EightHrTemp+degreeSign, inky_display.BLACK, font_medium) #Temp in 8 hrs
draw.text((x_TwoHrCond, 283), TwoHrCond, inky_display.BLACK, font_tiny) #Condition in 2 hrs
draw.text((x_FourHrCond, 283), FourHrCond, inky_display.BLACK, font_tiny) #Condition in 4 hrs
draw.text((x_SixHrCond, 283), SixHrCond, inky_display.BLACK, font_tiny) #Condition in 6 hrs
draw.text((x_EightHrCond, 283), EightHrCond, inky_display.BLACK, font_tiny) #Condition in 8 hrs
draw.text((x_TwoHrsTime, 239), TwoHrsTime, inky_display.BLACK, font_tiny) #Time in 2 hrs
draw.text((x_FourHrsTime, 239), FourHrsTime, inky_display.BLACK, font_tiny) #Time in 4 hrs
draw.text((x_SixHrsTime, 239), SixHrsTime, inky_display.BLACK, font_tiny) #Time in 6 hrs
draw.text((x_EightHrsTime, 239), EightHrsTime, inky_display.BLACK, font_tiny) #Time in 8 hrs
draw.text((292, 150), currentHumidity, inky_display.BLACK, font_small) #Current humidity in percentage
draw.text((292, 178), currentWind, inky_display.BLACK, font_small) #Current wind speed in MPH
draw.text((10, 190), currentDetailCond, inky_display.BLACK, font_medium2) #Current weather conditions, detailed
img.paste(cond_icons.CurrCondIcon(), (15, 60)) #Current Weather Icon
inky_display.set_image(img)
inky_display.show()