-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.py
More file actions
executable file
·57 lines (42 loc) · 1.17 KB
/
load.py
File metadata and controls
executable file
·57 lines (42 loc) · 1.17 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
import os
import sys
import aiohttp
import asyncio
from pprint import pprint
async def fetch(session: aiohttp.ClientSession, url: str, num: int):
async with session.post(url, json={"number": num}) as response:
return await response.json()
async def send(url: str, min_: int, max_: int):
async with aiohttp.ClientSession() as session:
req = []
for n in range(min_, max_ + 1):
req.append(fetch(session, url, n))
res = await asyncio.gather(*req, return_exceptions=True)
pprint(res)
def main():
loop = asyncio.get_event_loop()
min_ = os.getenv("MIN")
if not min_:
print("MIN env required")
return
try:
min_ = int(min_)
except ValueError:
print("MIN should be int")
return
max_ = os.getenv("MAX")
if not max_:
print("MAX env required")
return
try:
max_ = int(max_)
except ValueError:
print("MAX should be int")
url = os.getenv("URL")
if not url:
print("URL env required")
return
loop.run_until_complete(send(url, min_, max_))
if __name__ == "__main__":
main()