Toggle Navigation
Hatchery
Eggs
Weather
__init__.py
Users
Badges
Login
Register
__init__.py
raw
Content
import system, wifi, time, display, gc from time import sleep, localtime import urequests as requests import buttons icons = { "clear-day": chr(14), "clear-night": chr(47), "rain": chr(29), "snow": chr(24), "sleet": chr(101), "wind": chr(81), "fog": chr(100), "cloudy": chr(20), "partly-cloudy-day": chr(3), "partly-cloudy-night": chr(50), "degree": chr(61), "download": chr(62), "thermometer": chr(84), "tornado": chr(87), "comet": chr(114), "burningsun": chr(115), "alien": chr(118) } def getDisplayName(time): return str(time[2]) + "." + str(time[1]) + ". " + str(time[3]) + ":00" def connectToWifi(): if not wifi.status(): wifi.connect() display.drawFill(display.WHITE) display.drawText(10, 10, "Connecting to WiFi...", 0x000000, "Roboto_Regular12") display.flush() if not wifi.wait(): system.home() def drawSplash(): display.drawFill(display.WHITE) display.drawText(10, 10, "Getting weather from Dark Sky ...", 0x000000, "Roboto_Regular12") display.drawText(10, 20, "https://darksky.net/poweredby/", 0x000000, "Roboto_Regular12") display.flush() def fetchWeatherData(): r = requests.get("https://mch2022.badge.team/weather") gc.collect() data = r.json() r.close() return data connectToWifi() drawSplash() data = fetchWeatherData() hourly = data["hourly"]["data"] starttime = localtime(hourly[0]["time"]) index = starttime[3] if starttime[3] > 6: index = 12 - starttime[3] if starttime[3] > 12: index = 18 - starttime[3] if starttime[3] > 18: index = 24 - starttime[3] timepos = (10, 30) iconpos = (10, 60) temppos = (10, 105) display.drawFill(0xFFFFFF) display.drawLine(0, 26, display.width(), 26, 0x000000) display.drawLine(0, 44, display.width(), 44, 0x000000) display.drawText(5, 5, "Weather Forecast for Zeewolde, NL", 0x000000, "pixelade13") for p in range(4): dp = hourly[index + (p * 6)] time = localtime(dp["time"]) display.drawText(timepos[0] + p*11 + p*64, timepos[1], getDisplayName(time), 0x000000, "pixelade13") display.drawText(iconpos[0] + p*11 + p*64, iconpos[1], icons[dp["icon"]], 0x000000, "weather42") display.drawText(temppos[0] + p*11 + p*64, temppos[1], str(int(dp["temperature"]))+"*C", 0x000000, "DejaVuSans20") display.flush() def cbHome(p): if p: system.home() buttons.attach(buttons.BTN_HOME, cbHome)