forked from fenyx-it-academy/Class7-Python-Module-Week3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
41 lines (25 loc) · 770 Bytes
/
utils.py
File metadata and controls
41 lines (25 loc) · 770 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
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys
import json
import requests
from datetime import datetime
def api_func():
try:
res = requests.get("http://jsonplaceholder.typicode.com/users")
except Exception as x:
print("Something went wrong...")
sys.exit()
else:
result_object = res.json()
return result_object
def clean_result(lst):
new_list = []
for i in range (0,10):
new_list.append(lst[i]["id"])
new_list.append(lst[i]["name"])
new_list.append(lst[i]["username"])
new_list.append(lst[i]["email"])
return new_list
def create_file(new_list):
dt_string = datetime.now().strftime("%d%m%Y%H%M%S")
with open(f"users_{dt_string}.json", "w") as f:
json.dump(new_list, f)