add darkskies api to io python client

This commit is contained in:
brentru 2019-01-08 12:49:40 -05:00
parent 19f8cea7fc
commit fbbfe8ffae
2 changed files with 34 additions and 3 deletions

View file

@ -61,10 +61,10 @@ class Client(object):
self.base_url = base_url.rstrip('/')
def _compose_url(self, path, is_time=None):
if not is_time:
if is_time: # return a call to https://io.adafruit.com/api/v2/time/{unit}
return '{0}/api/{1}/{2}'.format(self.base_url, self.api_version, path)
else:
return '{0}/api/{1}/{2}/{3}'.format(self.base_url, self.api_version, self.username, path)
else: # return a call to https://io.adafruit.com/api/v2/time/{unit}
return '{0}/api/{1}/{2}'.format(self.base_url, self.api_version, path)
def _handle_error(self, response):
@ -161,6 +161,13 @@ class Client(object):
"""
timepath = "time/{0}".format(time)
return self._get(timepath, is_time=True)
def receive_weather(self, weather_id):
"""Get the specified weather record with current weather and all available forecast information.
:param int id: ID for forecast
"""
weatherpath = "integrations/weather/{0}".format(weather_id)
return self._get(weatherpath)
def receive(self, feed):
"""Retrieve the most recent value for the specified feed. Returns a Data

View file

@ -0,0 +1,24 @@
"""
Example of getting a darkskies forecast
from Adafruit IO.
"""
# import Adafruit IO REST client.
from Adafruit_IO import Client, Feed, RequestError
# Set to your Adafruit IO key.
# Remember, your key is a secret,
# so make sure not to publish it when you publish this code!
ADAFRUIT_IO_KEY = 'PASS'
# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username)
ADAFRUIT_IO_USERNAME = 'USER'
# Create an instance of the REST client.
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
forecast = aio.receive_weather(2153)
print(forecast)