Skip to content

Commit d535754

Browse files
committed
add unicode icons for weather
1 parent 03d42c5 commit d535754

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

modules/weather.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,37 @@ def get_conditions(self, query, channel):
7070
"Encountered an error contacting the OpenWeatherMap API")
7171
return
7272
weather = r.json()
73-
#print(weather)
73+
# print(weather)
7474
try:
7575
# grab the relevant data we want for formatting
7676
location = weather['name']
7777
conditions = weather['weather'][0]['main']
78+
79+
if conditions == "Clear":
80+
icon = '\N{sun}'
81+
elif conditions == "Rain" or conditions == "Drizzle":
82+
icon = '\N{cloud with rain}'
83+
elif conditions == "Thunderstorm":
84+
icon = '\N{cloud with lightning}'
85+
elif conditions == "Clouds":
86+
icon = '\N{cloud}'
87+
elif conditions == "Snow":
88+
icon = '\N{cloud with snow}'
89+
else:
90+
icon = '\N{fire}'
91+
7892
temp_f = round(weather['main']['temp'], 1)
7993
temp_c = round((temp_f - 32) * (5.0 / 9.0), 1)
80-
#sky = weather['weather'][0]['main']
81-
#print(sky)
94+
# sky = weather['weather'][0]['main']
95+
# print(sky)
8296
except KeyError:
8397
self.say(
8498
channel,
8599
"Unable to get weather data from results. Sorry.")
86100
return
87101
# return the formatted string of weather data
88-
return location + ': ' + conditions + ', ' + \
102+
# return location + ': ' + conditions + " 🌧️ " + ', ' + \
103+
return location + ': ' + conditions + ' ' + icon + ', ' + \
89104
str(temp_f) + '°F (' + str(temp_c) + '°C)'
90105

91106
def handle(self, event):

0 commit comments

Comments
 (0)