-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
merge_multi.py
49 lines (43 loc) · 1.62 KB
/
merge_multi.py
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
import requests
import yaml
import json
fullname = "ironscales"
locations = [
"https://appapi.ironscales.com/appapi/docs/partner-full/api-docs/appapi/get-token",
"https://appapi.ironscales.com/appapi/docs/partner-full/api-docs/appapi/mitigation",
"https://appapi.ironscales.com/appapi/docs/partner-full/api-docs/appapi/incident",
"https://appapi.ironscales.com/appapi/docs/partner-full/api-docs/appapi/campaigns",
"https://appapi.ironscales.com/appapi/docs/partner-full/api-docs/appapi/company",
"https://appapi.ironscales.com/appapi/docs/partner-full/api-docs/appapi/license",
]
full_item = {}
for location in locations:
ret = requests.get(location)
jsondata = ret.json()
for key, value in jsondata.items():
if isinstance(value, list):
#print("%s is list" % key)
for item in value:
try:
full_item[key].append(item)
except KeyError:
full_item[key] = [item]
elif isinstance(value, dict):
for subkey, subvalue in value.items():
try:
full_item[key][subkey] = subvalue
except KeyError:
full_item[key] = {}
full_item[key][subkey] = subvalue
else:
if len(value) > 0:
full_item[key] = value
#print(key, value)
#print(ret.text)
#print(ret.status_code)
#break
with open("%s_tmp.yaml" % fullname, "w+") as tmp:
tmp.write(yaml.dump(full_item))
with open("%s_tmp.json" % fullname, "w+") as tmp:
tmp.write(json.dumps(full_item))
print(full_item)