You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
627 B
20 lines
627 B
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) |