add darkskies api to io python client
This commit is contained in:
parent
19f8cea7fc
commit
fbbfe8ffae
2 changed files with 34 additions and 3 deletions
|
|
@ -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:
|
||||
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}
|
||||
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)
|
||||
|
||||
|
||||
def _handle_error(self, response):
|
||||
|
|
@ -162,6 +162,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
|
||||
instance whose value property holds the retrieved value.
|
||||
|
|
|
|||
24
examples/basics/darkskies.py
Normal file
24
examples/basics/darkskies.py
Normal 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)
|
||||
Loading…
Reference in a new issue