-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_options.py
107 lines (71 loc) · 2.56 KB
/
get_options.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# import requests
# import json
# from fields import *
# def find_val(d, key):
# s = json.dumps(d)
# try:
# start = s.index(key)
# except:
# return ''
# try:
# help_start = s.index("'help_text':", start) + len('"help_text":')
# str_start = s.index("'", help_start) + 1
# str_end = s.index("'", str_start)
# except:
# help_start = s.index('"help_text":', start) + len('"help_text":')
# str_start = s.index('"', help_start) + 1
# str_end = s.index('"', str_start)
# ret = s[str_start: str_end]
# return ret
# fin_disc = requests.options('https://www.courtlistener.com/api/rest/v3/financial-disclosures/')
# dic = disc_fields
# disc_field_keys_our = [i['name'] for key in disc_fields.keys() for i in disc_fields[key]]
# find_disc_data = fin_disc.json()['actions']['POST']
# d = {}
# for k in disc_field_keys_our:
# v = find_val(find_disc_data, k)
# # for _k in dic:
# # if _k['name'] == k:
# # k = _k.get('displayName') or _k.get('name')
# d[k] = v
# with open('flattened_disc.json', 'w') as f:
# f.write(json.dumps(d))
# for k, v in d.items():
# print(f'{k}: {v}')
# # person_data = person.json()['actions']['PUT']
# # print(':\n'.join(disc_field_keys_our))
import requests
import json
from fields import *
def find_val(d, key, sub_sect = ''):
s = json.dumps(d)
try:
abs_start = s.index(sub_sect)
start = s.index(key, abs_start)
except:
return ''
try:
help_start = s.index("'help_text':", start) + len('"help_text":')
str_start = s.index("'", help_start) + 1
str_end = s.index("'", str_start)
except:
help_start = s.index('"help_text":', start) + len('"help_text":')
str_start = s.index('"', help_start) + 1
str_end = s.index('"', str_start)
ret = s[str_start: str_end]
return ret
fin_disc = requests.options('https://www.courtlistener.com/api/rest/v3/financial-disclosures/')
dic = disc_fields
disc_field_keys_our = [i['name'] for key in disc_fields.keys() for i in disc_fields[key]]
find_disc_data = fin_disc.json()['actions']['POST']
d = {}
for k in dic:
print(f'\n{k}: ')
for item in dic[k]:
item = item['name']
v = find_val(find_disc_data, item, sub_sect = k)
print(f'\t{item}: {v} ')
# with open('flattened_disc.json', 'w') as f:
# f.write(json.dumps(d))
# person_data = person.json()['actions']['PUT']
# print(':\n'.join(disc_field_keys_our))