/ PyPortal_Discord / code.py
code.py
1 # SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 """ 6 This example will access shields.io API, grab the SVG graphic and then use 7 regular expression search to locate the number of online discord users, then 8 display it on a screen. 9 If you can find something that spits out text, we can display it! 10 """ 11 import time 12 import board 13 from adafruit_pyportal import PyPortal 14 from adafruit_portalbase.network import CONTENT_TEXT 15 16 # Set up where we'll be fetching data from 17 DATA_SOURCE = "https://img.shields.io/discord/327254708534116352.svg" 18 # a regular expression for finding the data within the SVG xml text! 19 DATA_LOCATION = [r">([0-9]+ online)<"] 20 21 cwd = ("/"+__file__).rsplit('/', 1)[0] 22 pyportal = PyPortal(url=DATA_SOURCE, regexp_path=DATA_LOCATION, 23 status_neopixel=board.NEOPIXEL, 24 default_bg=cwd+"/discord_background.bmp", 25 text_font=cwd+"/fonts/Collegiate-50.bdf", 26 text_position=(70, 216), text_color=0x000000) 27 28 while True: 29 try: 30 value = pyportal.fetch(force_content_type=CONTENT_TEXT) 31 print("Response is", value) 32 except RuntimeError as e: 33 print("Some error occured, retrying! -", e) 34 time.sleep(60)