-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
28 lines (21 loc) · 806 Bytes
/
parser.py
File metadata and controls
28 lines (21 loc) · 806 Bytes
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
import asyncio
import json
from aiohttp import ClientSession
from consts import P10_FILE_PATH, SISYPHUS_FILE_PATH
async def parser_data_url(session: ClientSession, url: str, file_path: str):
async with session.get(url=url) as response:
data_json = await response.json()
with open(file_path, "w") as f:
json.dump(data_json, f, indent=4)
async def create_tasks_parser(p10_url: str, sisyphus_url: str):
async with ClientSession() as session:
tasks = []
tasks.append(
asyncio.create_task(parser_data_url(session, p10_url, P10_FILE_PATH))
)
tasks.append(
asyncio.create_task(
parser_data_url(session, sisyphus_url, SISYPHUS_FILE_PATH)
)
)
await asyncio.gather(*tasks)