Toggle Navigation
Hatchery
Eggs
CTF Scoreboard
__init__.py
Users
Badges
Login
Register
__init__.py
raw
Content
import display import buttons import urequests import ujson import utime import wifi import mch22 import system url = "https://ctf.mch2022.org/json?view=scoreboard" def connectToWifi(): if not wifi.status(): wifi.connect() display.drawFill(display.WHITE) display.drawText(10, 10, "Connecting to WiFi...", 0x000000, "Roboto_Regular18") display.flush() if not wifi.wait(): mch22.exit_python() def loadScores(): connectToWifi() scores = urequests.get(url).json() displayScores(scores) def displayScores(scores): display.drawFill(display.BLACK) display.drawText(40, 10, "CTF Scoreboard", display.WHITE, "roboto_regular22") display.setDefaultFont("roboto_regular18") try: teams = len(scores["standings"]) amount = min(teams, 8) for i in range(amount): display.drawText(40, i * 25 + 40, scores["standings"][i]["team"]) display.drawText(265, i * 25 + 40, str(scores["standings"][i]["score"])) except: display.drawText(40, 100, "ERROR LOADING SCORES") display.flush() def on_action_btn(pressed): if pressed: loadScores() def on_home_btn(pressed): if pressed: mch22.exit_python() buttons.attach(buttons.BTN_A, on_action_btn) buttons.attach(buttons.BTN_HOME, on_home_btn) loadScores()