-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcond_icons.py
121 lines (89 loc) · 3.23 KB
/
cond_icons.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
# Weather Icons for Conditions
# Python file for icon library
import os, sys
from datetime import datetime, time
import configparser
from PIL import Image, ImageFont, ImageDraw
#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"])
#pyOWM Libraries
from pyowm.owm import OWM
from pyowm.utils import config
from pyowm.utils import timestamps
CurrDir = os.path.dirname(os.path.realpath(__file__)) + "/"
Resources = CurrDir + "resources/"
begin = time(19,0) #begins at 7:00 PM (19:00)
end = time(7,0) #ends at 7:00 AM
#OpenWeatherMap Integration
owm = OWM(api)
mgr = owm.weather_manager()
weather = mgr.weather_at_place(city+","+country).weather
one_call = mgr.one_call(lat, lon)
CurrCond = str(weather.status).title()
CurrCondDetail = str(weather.detailed_status).title()
#icon directory
ClearSun_ICON = Resources +"icons/sun.png"
ClearSunIconOutput = Image.open(ClearSun_ICON)
ClearMoon_ICON = Resources +"icons/moon.png"
ClearMoonIconOutput = Image.open(ClearMoon_ICON)
FewCloudsSun_ICON = Resources + "icons/few_clouds_sun.png"
FewCloudsSunIconOutput = Image.open(FewCloudsSun_ICON)
FewCloudsMoon_ICON = Resources + "icons/few_clouds_moon.png"
FewCloudsMoonIconOutput = Image.open(FewCloudsMoon_ICON)
Clouds_ICON = Resources + "icons/clouds.png"
CloudsIconOutput = Image.open(Clouds_ICON)
Sun_ICON = Resources + "icons/sun.png"
SunIconOutput = Image.open(Sun_ICON)
Rain_ICON = Resources + "icons/rain.png"
RainIconOutput = Image.open(Rain_ICON)
Drizzle_ICON = Resources + "icons/light_rain.png"
DrizzleIconOutput = Image.open(Drizzle_ICON)
Thunder_ICON = Resources + "icons/thunder.png"
ThunderIconOutput = Image.open(Thunder_ICON)
Thunderstorm_ICON = Resources + "icons/thunderstorm.png"
ThunderstormIconOutput = Image.open(Thunderstorm_ICON)
Snow_ICON = Resources + "icons/snow.png"
SnowIconOutput = Image.open(Snow_ICON)
Fog_ICON = Resources + "icons/fog.png"
FogIconOutput = Image.open(Fog_ICON)
def NightTime(begin, end, currTime=None):
currTime = currTime or datetime.now().time()
if begin < end:
return currTime >= begin and currTime <= end
else:
return currTime >= begin or currTime <= end
def CurrCondIcon():
if CurrCond == "Clear":
if NightTime(begin, end):
return ClearMoonIconOutput
else:
return ClearSunIconOutput
if CurrCond == "Clouds":
if CurrCondDetail == "Few Clouds":
if NightTime(begin, end):
return FewCloudsMoonIconOutput
else:
return FewCloudsSunIconOutput
if CurrCondDetail == "Scattered Clouds" or "Broken Clouds" or "Overcast Clouds":
return CloudsIconOutput
if CurrCond == "Rain":
return RainIconOutput
if CurrCond == "Drizzle":
return DrizzleIconOutput
if CurrCond == "Thunderstorm":
if CurrCondDetail == "Thunderstorm" or "Heavy Thunderstorm" or "Ragged Thunderstorm":
return ThunderIconOutput
else:
return ThunderstormIconOutput
if CurrCond == "Snow":
return SnowIconOutput
if CurrCond == "Mist" or "Smoke" or "Haze" or "Dust" or "Fog" or "Sand" or "Dust" or "Ash" or "Squall" or "Tornado":
return FogIconOutput