v.0.7.5 SimpleCounter
This commit is contained in:
@@ -112,4 +112,4 @@ class Weather_Checker():
|
||||
except OSError as e:
|
||||
print(f'Error: connection closed - {e}')
|
||||
finally:
|
||||
print('finally done.')
|
||||
print('finally, check done.')
|
||||
@@ -5,3 +5,4 @@ from .font_utils import *
|
||||
from .math_utils import *
|
||||
from .url_encode import URLEncoder
|
||||
from .http_utils import http_message
|
||||
from .simple_counter import SimpleCounter
|
||||
39
app/utils/simple_counter.py
Normal file
39
app/utils/simple_counter.py
Normal file
@@ -0,0 +1,39 @@
|
||||
class SimpleCounter:
|
||||
_value: int
|
||||
|
||||
def __init__(self):
|
||||
self._value = 0
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
self._value = value
|
||||
|
||||
# Arithmetic operators
|
||||
def __add__(self, other):
|
||||
return self._value + other
|
||||
|
||||
def __sub__(self, other):
|
||||
return self._value - other
|
||||
|
||||
# In-place operators
|
||||
def __iadd__(self, other):
|
||||
self._value += other
|
||||
return self
|
||||
|
||||
def __isub__(self, other):
|
||||
self._value -= other
|
||||
return self
|
||||
|
||||
# Conversion and representation
|
||||
def __int__(self):
|
||||
return self._value
|
||||
|
||||
def __str__(self):
|
||||
return str(self._value)
|
||||
|
||||
def __repr__(self):
|
||||
return f"SimpleCounter(value={self._value})"
|
||||
24
main.py
24
main.py
@@ -1,29 +1,35 @@
|
||||
from app.display import NeoPixel_64x64
|
||||
from app.display.fonts import font_5x7
|
||||
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
|
||||
from app.utils import sync_ntp_time, get_datetime_string, get_german_datetime # Time-related functions
|
||||
from app.utils import SimpleCounter
|
||||
from app.web import Wlan
|
||||
import time
|
||||
import uasyncio as asyncio # type: ignore
|
||||
|
||||
CITY_LIST: list[str]= ["Großhansdorf","Columbus", "London", "Ebeltoft", "Tokio"]
|
||||
CITY_LIST: list[str]= sorted(["Großhansdorf","Columbus", "London", "Ebeltoft", "Tokio"])
|
||||
|
||||
async def weather_check_task(weather_checker):
|
||||
async def weather_check_task(weather_checker: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
|
||||
await asyncio.sleep(3 * 60) # Non-blocking sleep
|
||||
|
||||
async def other_task():
|
||||
async def print_time_task() -> None:
|
||||
simpleCnt: SimpleCounter = SimpleCounter()
|
||||
while True:
|
||||
print("Other task running...")
|
||||
await asyncio.sleep(2)
|
||||
dt1:int = get_datetime_string()
|
||||
dt2:int = get_german_datetime()
|
||||
simpleCnt+=1
|
||||
print(f"print_time_task running... {simpleCnt.value%16} {dt1} {dt2}")
|
||||
await asyncio.sleep(10)
|
||||
|
||||
|
||||
async def main(weather_checker)->None:
|
||||
async def main(weather_checker:Weather_Checker)->None:
|
||||
# Run both tasks concurrently
|
||||
await asyncio.gather(weather_check_task(weather_checker), other_task())
|
||||
await asyncio.gather(weather_check_task(weather_checker), print_time_task())
|
||||
|
||||
# Programm Startpunkt
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user