diff --git a/demo/func/__init__.py b/demo/func/__init__.py new file mode 100644 index 0000000..10c0679 --- /dev/null +++ b/demo/func/__init__.py @@ -0,0 +1 @@ +from . import secondary_functions \ No newline at end of file diff --git a/demo/func/secondary_functions.py b/demo/func/secondary_functions.py new file mode 100644 index 0000000..5fc9107 --- /dev/null +++ b/demo/func/secondary_functions.py @@ -0,0 +1,20 @@ +import time +import asyncio +from aiohttp.web_ws import WebSocketResponse + + +async def time_response(ws: WebSocketResponse, delay: int = 60): + while True: + new_time: time.gmtime = time.gmtime(time.time()) + hour = new_time.tm_hour + 3 + if hour >= 24: + hour = hour - 24 + minutes = new_time.tm_min + if minutes < 10: + minutes = f'0{minutes}' + result_response = f'Время: {hour}:{minutes}' + try: + await ws.send_str(result_response) + await asyncio.sleep(delay) + except ConnectionResetError: + await asyncio.sleep(delay) \ No newline at end of file