-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpoll.py
More file actions
36 lines (30 loc) · 1.07 KB
/
poll.py
File metadata and controls
36 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import asyncio
from httpx import AsyncClient, Response, Timeout
from dotenv import load_dotenv
from loader import URL_TG
from reqs import make_order
load_dotenv()
async def main():
updid = 0
while True:
async with AsyncClient() as client:
resp: Response = await client.get(
f'{URL_TG}getUpdates?limit=10&offset={updid}&allowed_updates=["callback_query"]',
timeout=Timeout(connect=5, read=12, write=5, pool=2)
)
r = resp.json()
res = r['result']
if r['ok'] and res:
updid = res[-1]['update_id']+1
cb = res[-1]['callback_query']
data = cb['data'].split(':')
res = await make_order(*data)
txt = cb["data"] if res else "!ERROR!!!"
await client.get(f'{URL_TG}answerCallbackQuery?callback_query_id={cb["id"]}&text={txt}') # &url=
print(data)
print('.', end='')
# await asyncio.sleep(1)
try:
asyncio.run(main())
except KeyboardInterrupt:
print('Stopped.')