-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathparser.py
More file actions
40 lines (31 loc) · 1.11 KB
/
parser.py
File metadata and controls
40 lines (31 loc) · 1.11 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
import csv
import time
import httpx
from loguru import logger
def parse_csv_file():
emails = []
start_time = time.monotonic()
with open('hw_7/emails_file.csv') as csv_file:
reader = csv.reader(csv_file)
logger.info('Request lasted {0} seconds'.format(
time.monotonic() - start_time)
)
emails = list(reader)
return emails
def flatten(lst_emails):
return [lst_element for sublist in lst_emails for lst_element in sublist]
async def get_data_json():
async with httpx.AsyncClient() as client:
url = 'https://jsonplaceholder.typicode.com/users/'
start_time = time.monotonic()
response = await client.get(url)
end_time = time.monotonic()
logger.info('The request lasted {0} seconds'.format(
end_time - start_time)
)
return response.json()
def get_ready_dict_with_emails_and_ids(people_data, emails_ids):
for person_data in people_data:
if person_data['email'] in emails_ids:
emails_ids[person_data.get('email')] = person_data['id']
return emails_ids