We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b25e1d7 commit b02326dCopy full SHA for b02326d
0x15-api/2-export_to_JSON.py
@@ -0,0 +1,29 @@
1
+#!/usr/bin/python3
2
+"""import api from a url"""
3
+import json
4
+import requests
5
+import sys
6
+
7
+if __name__ == "__main__":
8
+ try:
9
+ id = int(sys.argv[1])
10
+ url = "https://jsonplaceholder.typicode.com"
11
+ res = requests.get('{}/users/{}'.format(url, id)).json()
12
+ res_todo = requests.get("{}/todos".format(url),
13
+ params={"userId": id}).json()
14
+ name = res.get("username")
15
+ user_data = list(map(
16
+ lambda x: {
17
+ "task": x.get("title"),
18
+ "completed": x.get("completed"),
19
+ "username": name
20
+ },
21
+ res_todo
22
+ ))
23
+ with open('{}.json'.format(id), 'w') as apidata:
24
+ data = {
25
+ "{}".format(id): user_data
26
+ }
27
+ json.dump(data, apidata)
28
+ except ValueError:
29
+ pass
0 commit comments