-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (51 loc) · 2.2 KB
/
main.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
import fields
from utils import *
from csv import DictWriter
from argparse import ArgumentParser
def main(max_row):
url = 'https://www.courtlistener.com/api/rest/v3/financial-disclosures'
count = 1
row_num = 1
with open('data/output.csv', 'w', newline = '', encoding = 'utf-8') as f:
writer = DictWriter(f, fields.all_field_names)
writer.writeheader()
while count:
data = req(url)
people = data.get('results')
#rate limited
while not people:
#wait 15 mins
print('sleeping...')
sleep_progress(60 * 15)
data = req(url)
people = data.get('results')
for person in people:
print(f'starting on {person["resource_uri"]}')
#compute here and save so not recomputing unnecesarily
non_disc_fields = get_person_fields(person) | get_common_fields(person)
for disc_type in fields.disc_types:
print(f'\tGrabbing {disc_type}')
#each individual disclosure per type per person
for disc in person[disc_type]:
try:
row = get_disclosure_fields(disc, disc_type) | non_disc_fields | {'Disclosure Type': disc_type}
writer.writerow(row)
except:
...
print(f'row: {row_num}')
if row_num >= max_row:
print('\n\nFINISHED')
quit()
row_num += 1
url = data.get('next')
#reached end
if not url:
break
count += len(people)
print(f'On person {count}')
print('\n\nFINISHED')
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('-max', type = float, default = float('inf'))
args = parser.parse_args()
main(args.max)