Skip to content

Instantly share code, notes, and snippets.

@jasoncoon
Created March 3, 2019 20:59
Show Gist options
  • Save jasoncoon/53f84c5f0c061bdf3df0e7a7a5db0947 to your computer and use it in GitHub Desktop.
Save jasoncoon/53f84c5f0c061bdf3df0e7a7a5db0947 to your computer and use it in GitHub Desktop.
Python code for a Tindie order tracker built with an Adafruit PyPortal
import time
import board
from adafruit_pyportal import PyPortal
# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
tindie_username = secrets['tindie_username']
tindie_api_key = secrets['tindie_api_key']
# Set up where we'll be fetching data from
DATA_SOURCE = "https://www.tindie.com/api/v1/order/?format=json&username=" + \
tindie_username + "&api_key=" + tindie_api_key + "&limit=1"
DATA_LOCATION = ["meta", "total_count"]
# the current working directory (where this file is)
cwd = ("/" + __file__).rsplit('/', 1)[0]
# Initialize the pyportal object and let us know what data to fetch and where
# to display it
pyportal = PyPortal(url=DATA_SOURCE,
json_path=DATA_LOCATION,
status_neopixel=board.NEOPIXEL,
default_bg=cwd + "/egl_background.bmp",
text_font=cwd + "/fonts/Collegiate-50.bdf",
text_position=(165, 140),
text_color=0xFFFFFF,
caption_text="https://evilgeniuslabs.org",
caption_font=cwd + "/fonts/Collegiate-24.bdf",
caption_position=(50, 200),
caption_color=0xFFFFFF,)
# track the last value so we can play a sound when it updates
last_value = 0
while True:
try:
value = pyportal.fetch()
print("Response is", value)
if last_value < value: # ooh it went up!
print("New Order!")
pyportal.play_file(cwd + "/coin.wav") # uncomment make a noise!
last_value = value
except (ValueError, RuntimeError) as e:
print("Some error occured, retrying! -", e)
time.sleep(60) # wait a minute before getting again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment