File tree 1 file changed +9
-4
lines changed
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 3
3
for subscribing to the Adafruit IO Weather Service
4
4
Note: This feature is avaliable for IO Plus Subscribers ONLY
5
5
6
+ API Documentation: https://io.adafruit.com/services/weather
7
+
6
8
Author: Brent Rubell for Adafruit Industries
7
9
"""
8
10
@@ -93,10 +95,13 @@ def parseForecast(forecast_data):
93
95
"""
94
96
# incoming data is a utf-8 string, encode it as a json object
95
97
forecast = json .loads (forecast_data )
96
- print (forecast )
97
- print ('It is {0} and {1} F.' .format (forecast ['summary' ], forecast ['temperature' ]))
98
- print ('with a humidity of {0}% and a wind speed of {1}mph.' .format (forecast ['humidity' ], forecast ['windSpeed' ]))
99
- print ('There is a {0}% chance of precipitation. It feels like {1} F' .format (forecast ['precipProbability' ], forecast ['apparentTemperature' ]))
98
+ try :
99
+ print ('It is {0} and of {1}F.' .format (forecast ['summary' ], forecast ['temperature' ]))
100
+ except KeyError :
101
+ # future weather forecasts return a high and low temperature, instead of 'temperature'
102
+ print ('It will be {0} with a high of {1}F and a low of {2}F.' .format (forecast ['summary' ], forecast ['temperatureLow' ], forecast ['temperatureHigh' ]))
103
+ print ('with a humidity of {0}% and a wind speed of {1}mph.' .format (forecast ['humidity' ], forecast ['windSpeed' ]))
104
+ print ('There is a {0}% chance of precipitation.' .format (forecast ['precipProbability' ]))
100
105
101
106
# Create an MQTT client instance.
102
107
client = MQTTClient (ADAFRUIT_IO_USERNAME , ADAFRUIT_IO_KEY )
You can’t perform that action at this time.
0 commit comments