From 5edc3beb782035e9f1bc9c176038eefe9459ebf2 Mon Sep 17 00:00:00 2001 From: kirill Date: Sat, 3 Jun 2023 16:40:56 +0300 Subject: [PATCH] add package secondary_functions Signed-off-by: kirill --- demo/func/__init__.py | 1 + demo/func/secondary_functions.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 demo/func/__init__.py create mode 100644 demo/func/secondary_functions.py 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