1+ """
2+ 'weather.py'
3+ ================================================
4+ Dark Sky Hyperlocal for IO Plus
5+ with Adafruit IO API
6+
7+ Author(s): Brent Rubell for Adafruit Industries
8+ """
9+ # Import JSON for forecast parsing
10+ import json
11+ # Import Adafruit IO REST client.
12+ from Adafruit_IO import Client , Feed , RequestError
13+
14+ # Set to your Adafruit IO key.
15+ ADAFRUIT_IO_USERNAME = 'YOUR_IO_USERNAME'
16+ ADAFRUIT_IO_KEY = 'YOUR_IO_PASSWORD'
17+
18+ # Create an instance of the REST client.
19+ aio = Client (ADAFRUIT_IO_USERNAME , ADAFRUIT_IO_KEY )
20+
21+ # Grab the weather JSON
22+ weather = aio .receive_weather (1234 )
23+ weather = json .dumps (weather )
24+ forecast = json .loads (weather )
25+
26+ # Parse the current forecast
27+ current = forecast ['current' ]
28+ print ('Current Forecast' )
29+ print ('It is {0} and {1}.' .format (current ['summary' ], current ['temperature' ]))
30+
31+ # Parse the two day forecast
32+ forecast_days_2 = forecast ['forecast_days_2' ]
33+ print ('\n Weather in Two Days' )
34+ print ('It will be {0} with a high of {1}F and a low of {2}F.' .format (
35+ forecast_days_2 ['summary' ], forecast_days_2 ['temperatureLow' ], forecast_days_2 ['temperatureHigh' ]))
36+
37+ # Parse the five day forecast
38+ forecast_days_5 = forecast ['forecast_days_5' ]
39+ print ('\n Weather in Five Days' )
40+ print ('It will be {0} with a high of {1}F and a low of {2}F.' .format (
41+ forecast_days_5 ['summary' ], forecast_days_5 ['temperatureLow' ], forecast_days_5 ['temperatureHigh' ]))
0 commit comments