Toggle Navigation
Hatchery
Eggs
cccamp19
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import badge, esp, easywifi, ugfx, gc, easydraw, deepsleep import urequests as requests from random import choice from . import dirtyurl appname = 'cccamp19' badge.init() ugfx.init() ugfx.clear(ugfx.WHITE) ugfx.flush(ugfx.LUT_FULL) easywifi.enable(False) if easywifi.state==False: easydraw.msg("Unable to connect to network!","FAILURE") easydraw.msg("Waiting 5 seconds to try again!") badge.eink_busy_wait() esp.rtcmem_write_string(appname) deepsleep.start_sleeping(5000) def throwError(error = "unknown"): if type(error) is list: easydraw.msg("An error occurred:", "Error", True) for message in error: easydraw.msg(message) else: easydraw.msg(error,"Error", True) easydraw.msg("Waiting 30 seconds to try again!") badge.eink_busy_wait() esp.rtcmem_write_string(appname) deepsleep.start_sleeping(30000) def getPic(url): global data # Get converted picture try: data = requests.get(url) except: throwError("Generative image service broken or unavailable") try: image = data.content except: data.close() gc.collect() throwError("Image invalid or file too big") data.close() gc.collect() return image synonyms = [""] baseURL = "https://cccamp19.bleeptrack.de/api/?greyscale=1&w=128&h=128&filetype=png&text=" nick = badge.nvs_get_str("owner", "name", "badge.team") safenick = dirtyurl.encode(nick) url = baseURL + safenick + dirtyurl.encode(choice(synonyms)) image = getPic(url) # Write image to display multiple times for contrast for i in range(3): badge.eink_png(0, 0, image) ugfx.string_box(128+15,round(ugfx.height()/2)-round(36/2),128-15, ugfx.height(), nick, "PermanentMarker36", ugfx.BLACK, ugfx.justifyCenter) ugfx.flush(ugfx.GREYSCALE) badge.eink_busy_wait() deepsleep.start_sleeping()