v.0.7.4 asyncio
This commit is contained in:
34
main.py
34
main.py
@@ -4,19 +4,34 @@ from app.tryout import Font_Checker, Weather_Checker, Emoji_Checker
|
|||||||
from app.utils import show_system_load, sync_ntp_time, get_datetime_string, get_german_datetime
|
from app.utils import show_system_load, sync_ntp_time, get_datetime_string, get_german_datetime
|
||||||
from app.web import Wlan
|
from app.web import Wlan
|
||||||
import time
|
import time
|
||||||
|
import uasyncio as asyncio # type: ignore
|
||||||
|
|
||||||
CITY_LIST: list[str]= ["Großhansdorf","Columbus", "London", "Ebeltoft", "Tokio"]
|
CITY_LIST: list[str]= ["Großhansdorf","Columbus", "London", "Ebeltoft", "Tokio"]
|
||||||
|
|
||||||
|
async def weather_check_task(weather_checker):
|
||||||
|
while True:
|
||||||
|
for city in CITY_LIST:
|
||||||
|
weather_checker.check(city=city, lang="de", test_mode=False)
|
||||||
|
print(f"Checked {city}")
|
||||||
|
await asyncio.sleep(1 * 60) # Non-blocking sleep
|
||||||
|
|
||||||
|
async def other_task():
|
||||||
|
while True:
|
||||||
|
print("Other task running...")
|
||||||
|
await asyncio.sleep(2)
|
||||||
|
|
||||||
|
|
||||||
|
async def main(weather_checker)->None:
|
||||||
|
# Run both tasks concurrently
|
||||||
|
await asyncio.gather(weather_check_task(weather_checker), other_task())
|
||||||
|
|
||||||
# Programm Startpunkt
|
# Programm Startpunkt
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
display = NeoPixel_64x64()
|
display = NeoPixel_64x64()
|
||||||
wlan: Wlan = Wlan( )
|
wlan: Wlan = Wlan( )
|
||||||
wlan.connect( ssid="Wokwi-Wlan", password="12345678")
|
wlan.connect( ssid="Wokwi-Wlan", password="12345678")
|
||||||
|
|
||||||
if sync_ntp_time():
|
sync_ntp_time()
|
||||||
time_str: str = get_datetime_string('time')
|
|
||||||
ger_time_str: str = get_german_datetime()
|
|
||||||
print( f"time is: {time_str[:5]} & german: {ger_time_str}" )
|
|
||||||
|
|
||||||
# font_checker : Font_Checker = Font_Checker( display)
|
# font_checker : Font_Checker = Font_Checker( display)
|
||||||
# font_checker.fonts_check(pretty=False)
|
# font_checker.fonts_check(pretty=False)
|
||||||
@@ -28,9 +43,12 @@ if __name__ == '__main__':
|
|||||||
display.set_font(font_5x7)
|
display.set_font(font_5x7)
|
||||||
weather_checker: Weather_Checker = Weather_Checker( display=display)
|
weather_checker: Weather_Checker = Weather_Checker( display=display)
|
||||||
|
|
||||||
while True:
|
|
||||||
for city in sorted(CITY_LIST):
|
|
||||||
weather_checker.check(city=city, lang="de", test_mode=False)
|
# while True:
|
||||||
time.sleep(5*60)
|
# for city in sorted(CITY_LIST):
|
||||||
|
# weather_checker.check(city=city, lang="de", test_mode=False)
|
||||||
|
# time.sleep(5*60)
|
||||||
|
|
||||||
# show_system_load()
|
# show_system_load()
|
||||||
|
asyncio.run(main(weather_checker))
|
||||||
|
|||||||
Reference in New Issue
Block a user