File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 33for subscribing to the Adafruit IO Weather Service
44Note: This feature is avaliable for IO Plus Subscribers ONLY
55
6+ API Documentation: https://io.adafruit.com/services/weather
7+
68Author: Brent Rubell for Adafruit Industries
79"""
810
@@ -93,10 +95,13 @@ def parseForecast(forecast_data):
9395 """
9496 # incoming data is a utf-8 string, encode it as a json object
9597 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' ]))
100105
101106# Create an MQTT client instance.
102107client = MQTTClient (ADAFRUIT_IO_USERNAME , ADAFRUIT_IO_KEY )
You can’t perform that action at this time.
0 commit comments