Toggle Navigation
Hatchery
Eggs
teletekst
__init__.py
Users
Badges
Login
Register
__init__.py
raw
Content
import urequests as requests import display import buttons import wifi from time import sleep wifi.connect() sleep(4) # this is how you deal with race conditions. it will never cause trouble position = 0 page = [1, 0, 0] display.drawFill(display.BLACK) host = "20.121.51.42" # no guarantees this will stay up def render_page(): data = requests.get(f'http://{host}/{"".join(str(x) for x in page)}').json()['content'] raw_data = [entry.split('<') for entry in data.split('">')] processed_data = [] for entry in raw_data: processed_data.append( entry[0].replace('', '\uf020').replace('', '\uf023').replace('', '\uf02c')) for line_endings in entry[1:]: for _ in range(line_endings.count('\n')): processed_data.append('\n') processed_data = ''.join(processed_data).splitlines() display.drawRect(0, 0, 800, 219, True, display.BLACK) display.flush() for j, line in enumerate(processed_data): display.drawText(0, j * 8, line, 0xFFFFFF, "7x5") display.flush() render_position_indicator() def confirm_input(event): global position if event: position += 1 render_position_indicator() if position == 3: try: render_page() except: ... position = 0 render_position_indicator() display.flush() def reject_input(event): global position if event: position -= 1 if position == -1: position = 2 render_position_indicator() def render_position_indicator(): global position display.drawRect(0, 235, 800, 2, True, display.BLACK) display.drawRect(50 + position * 10, 235, 10, 2, True, display.CYAN) display.flush() def increase(event): if event: page[position] += 1 page[position] = page[position] % 10 display.drawRect(50 + position * 10, 220, 10, 20, True, display.BLACK) display.drawText(50 + position * 10, 220, str(page[position])) display.flush() def decrease(event): if event: page[position] -= 1 page[position] = abs(page[position]) % 10 display.drawRect(50 + position * 10, 220, 10, 20, True, display.BLACK) display.drawText(50 + position * 10, 220, str(page[position])) display.flush() buttons.attach(buttons.BTN_A, confirm_input) buttons.attach(buttons.BTN_B, reject_input) buttons.attach(buttons.BTN_UP, increase) buttons.attach(buttons.BTN_DOWN, decrease) buttons.attach(buttons.BTN_RIGHT, confirm_input) buttons.attach(buttons.BTN_LEFT, reject_input) render_position_indicator() for _ in range(3): increase(True) decrease(True) confirm_input(True)