Skip to content

Commit 32661c2

Browse files
brentrubrentru
brentru
authored and
brentru
committed
adding example of getting random data by id
1 parent 02634fb commit 32661c2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

examples/api/random_data.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
'random_data.py'
3+
================================================
4+
Example for accessing the Adafruit IO Random
5+
Data Service.
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 = 'USER'
16+
ADAFRUIT_IO_KEY = 'KEY'
17+
18+
# Create an instance of the REST client.
19+
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
20+
21+
generator_id = 1461
22+
23+
# Get the specified randomizer record with its current value and related details.
24+
random_data = aio.receive_random(generator_id)
25+
# Parse the API response
26+
data = json.dumps(random_data)
27+
data = json.loads(data)
28+
print('Random Data: {0}'.format(data['value']))

0 commit comments

Comments
 (0)