You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Disconnected function will be called when the client disconnects.
69
71
print('Disconnected from Adafruit IO!')
70
72
sys.exit(1)
71
73
74
+
# pylint: disable=unused-argument
72
75
defmessage(client, topic, payload):
73
76
"""Message function will be called when any subscribed forecast has an update.
74
77
Weather data is updated at most once every 20 minutes.
75
78
"""
76
79
# forecast based on mqtt topic
77
80
iftopic=='current':
78
-
# Print out today's forecast
79
-
today_forecast=payload
80
-
print('\nCurrent Forecast')
81
-
parseForecast(today_forecast)
81
+
# Print out today's forecast
82
+
today_forecast=payload
83
+
print('\nCurrent Forecast')
84
+
parseForecast(today_forecast)
82
85
eliftopic=='forecast_days_2':
83
-
# Print out tomorrow's forecast
84
-
two_day_forecast=payload
85
-
print('\nWeather in Two Days')
86
-
parseForecast(two_day_forecast)
86
+
# Print out tomorrow's forecast
87
+
two_day_forecast=payload
88
+
print('\nWeather in Two Days')
89
+
parseForecast(two_day_forecast)
87
90
eliftopic=='forecast_days_5':
88
-
# Print out forecast in 5 days
89
-
five_day_forecast=payload
90
-
print('\nWeather in 5 Days')
91
-
parseForecast(five_day_forecast)
91
+
# Print out forecast in 5 days
92
+
five_day_forecast=payload
93
+
print('\nWeather in 5 Days')
94
+
parseForecast(five_day_forecast)
92
95
93
96
defparseForecast(forecast_data):
94
-
"""Parses and prints incoming forecast data
95
-
"""
96
-
# incoming data is a utf-8 string, encode it as a json object
97
-
forecast=json.loads(forecast_data)
98
-
99
-
# Print out the forecast
100
-
try:
101
-
print('It is {0} and {1}F.'.format(forecast['summary'], forecast['temperature']))
102
-
exceptKeyError:
103
-
# future weather forecasts return a high and low temperature, instead of 'temperature'
104
-
print('It will be {0} with a high of {1}F and a low of {2}F.'.format(forecast['summary'], forecast['temperatureLow'], forecast['temperatureHigh']))
105
-
print('with a humidity of {0}%, a wind speed of {1}mph, and a {2}% chance of precipitation.'.format(forecast['humidity'], forecast['windSpeed'], forecast['precipProbability']))
97
+
"""Parses and prints incoming forecast data
98
+
"""
99
+
# incoming data is a utf-8 string, encode it as a json object
100
+
forecast=json.loads(forecast_data)
101
+
# Print out the forecast
102
+
try:
103
+
print('It is {0} and {1}F.'.format(forecast['summary'], forecast['temperature']))
104
+
exceptKeyError:
105
+
# future weather forecasts return a high and low temperature, instead of 'temperature'
106
+
print('It will be {0} with a high of {1}F and a low of {2}F.'.format(
0 commit comments