Skip to content

Commit fbbfe8f

Browse files
author
brentru
committed
add darkskies api to io python client
1 parent 19f8cea commit fbbfe8f

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

Adafruit_IO/client.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ def __init__(self, username, key, proxies=None, base_url='https://io.adafruit.co
6161
self.base_url = base_url.rstrip('/')
6262

6363
def _compose_url(self, path, is_time=None):
64-
if not is_time:
64+
if is_time: # return a call to https://io.adafruit.com/api/v2/time/{unit}
65+
return '{0}/api/{1}/{2}'.format(self.base_url, self.api_version, path)
66+
else:
6567
return '{0}/api/{1}/{2}/{3}'.format(self.base_url, self.api_version, self.username, path)
66-
else: # return a call to https://io.adafruit.com/api/v2/time/{unit}
67-
return '{0}/api/{1}/{2}'.format(self.base_url, self.api_version, path)
6868

6969

7070
def _handle_error(self, response):
@@ -161,6 +161,13 @@ def receive_time(self, time):
161161
"""
162162
timepath = "time/{0}".format(time)
163163
return self._get(timepath, is_time=True)
164+
165+
def receive_weather(self, weather_id):
166+
"""Get the specified weather record with current weather and all available forecast information.
167+
:param int id: ID for forecast
168+
"""
169+
weatherpath = "integrations/weather/{0}".format(weather_id)
170+
return self._get(weatherpath)
164171

165172
def receive(self, feed):
166173
"""Retrieve the most recent value for the specified feed. Returns a Data

examples/basics/darkskies.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
Example of getting a darkskies forecast
3+
from Adafruit IO.
4+
"""
5+
# import Adafruit IO REST client.
6+
from Adafruit_IO import Client, Feed, RequestError
7+
8+
# Set to your Adafruit IO key.
9+
# Remember, your key is a secret,
10+
# so make sure not to publish it when you publish this code!
11+
ADAFRUIT_IO_KEY = 'PASS'
12+
13+
# Set to your Adafruit IO username.
14+
# (go to https://accounts.adafruit.com to find your username)
15+
ADAFRUIT_IO_USERNAME = 'USER'
16+
17+
# Create an instance of the REST client.
18+
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
19+
20+
21+
22+
forecast = aio.receive_weather(2153)
23+
24+
print(forecast)

0 commit comments

Comments
 (0)