feat: Add API polling for dynamic sign display
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
30
protosign.py
30
protosign.py
@@ -3,6 +3,9 @@
|
||||
|
||||
from vestactrl import setup_digits, board_init_uart
|
||||
import textwrap
|
||||
import urllib2
|
||||
import json
|
||||
import time
|
||||
|
||||
def send_sign(text):
|
||||
"""
|
||||
@@ -26,8 +29,31 @@ def send_sign(text):
|
||||
setup_digits(board_lines, left_to_right_swap=False, real_hw=True)
|
||||
|
||||
|
||||
def poll_and_display():
|
||||
"""
|
||||
Polls the Protospace API and displays the sign message.
|
||||
"""
|
||||
last_message = ""
|
||||
url = 'https://api.my.protospace.ca/stats/'
|
||||
|
||||
while True:
|
||||
try:
|
||||
response = urllib2.urlopen(url)
|
||||
data = json.load(response)
|
||||
message = data.get('sign')
|
||||
|
||||
if message and message != last_message:
|
||||
print "Updating sign with new message: " + message
|
||||
send_sign(message)
|
||||
last_message = message
|
||||
|
||||
except (urllib2.URLError, ValueError, KeyError) as e:
|
||||
print "Error: {}".format(e)
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Initialize communication with the board.
|
||||
board_init_uart()
|
||||
message = "This is a test of the protosign script. This message should wrap across multiple lines and be truncated if it is too long to fit on the display."
|
||||
send_sign(message)
|
||||
poll_and_display()
|
||||
|
Reference in New Issue
Block a user