forked from fecgov/openFEC
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoints_walk.py
128 lines (115 loc) · 5.25 KB
/
endpoints_walk.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
"""
this is a simple scipt to test the status of all endpoints after deployment
Pls note that some endpoints need required parameters and some example data
are given hereself.
the endpoints list could be exapanded or improved in the future.
Note: on the production tier, api_key is required.
quick server list for reference:
prod: https://api.open.fec.gov
stage: https://api-stage.open.fec.gov
dev: https://fec-dev-api.app.cloud.gov
"""
import os
import click
import requests
COMMITTEE_ID = "C00496067"
CANDIDATE_ID = "P40002172"
SUB_ID = "1"
COMMITTEE_TYPE = "P"
# a list of endpoints pulled from rest.py
endpoints = [
"/committees/?api_key={api_key}",
"/candidates/?api_key={api_key}",
"/candidates/search/?api_key={api_key}",
"/candidate/{candidate_id}/?api_key={api_key}",
"/committee/{committee_id}/candidates/?api_key={api_key}",
"/candidate/{candidate_id}/history/?api_key={api_key}",
"/candidate/{candidate_id}/history/2018/?api_key={api_key}",
"/committee/{committee_id}/candidates/history/?api_key={api_key}",
"/committee/{committee_id}/candidates/history/2018/?api_key={api_key}",
"/committee/{committee_id}/?api_key={api_key}",
"/candidate/{candidate_id}/committees/?api_key={api_key}",
"/committee/{committee_id}/history/?api_key={api_key}",
"/committee/{committee_id}/history/2018/?api_key={api_key}",
"/candidate/{candidate_id}/committees/history/?api_key={api_key}",
"/candidate/{candidate_id}/committees/history/2018/?api_key={api_key}",
"/totals/{committee_type}/?api_key={api_key}",
"/committee/{committee_id}/totals/?api_key={api_key}",
"/candidate/{candidate_id}/totals/?api_key={api_key}",
"/reports/{committee_type}/?api_key={api_key}",
"/committee/{committee_id}/reports/?api_key={api_key}",
"/names/candidates/?q=clinton&api_key={api_key}",
"/names/committees/?q=clinton&api_key={api_key}",
"/schedules/schedule_a/{sub_id}/?two_year_transaction_period=2018&api_key={api_key}",
"/schedules/schedule_a/efile/?api_key={api_key}",
"/schedules/schedule_b/{sub_id}/?api_key={api_key}",
"/schedules/schedule_b/efile/?api_key={api_key}",
"/schedules/schedule_c/?api_key={api_key}",
"/schedules/schedule_d/?api_key={api_key}",
"/schedules/schedule_e/?api_key={api_key}",
"/schedules/schedule_e/efile/?api_key={api_key}",
"/schedules/schedule_f/{sub_id}/?api_key={api_key}",
"/elections/?cycle=2018&office=president&api_key={api_key}",
"/elections/search/?api_key={api_key}",
"/elections/summary/?cycle=2018&office=president&api_key={api_key}",
"/state-election-office/?state=MD&api_key={api_key}",
"/election-dates/?api_key={api_key}",
"/reporting-dates/?api_key={api_key}",
"/calendar-dates/?api_key={api_key}",
"/calendar-dates/export/?api_key={api_key}",
"/rad-analyst/?api_key={api_key}",
"/efile/filings/?api_key={api_key}",
"/totals/by_entity/?cycle=2018&api_key={api_key}",
"/audit-primary-category/?api_key={api_key}",
"/audit-category/?api_key={api_key}",
"/audit-case/?api_key={api_key}",
"/names/audit_candidates/?q=clinton&api_key={api_key}",
"/names/audit_committees/?q=&clinton&api_key={api_key}",
"/schedules/schedule_a/by_size/by_candidate/?candidate_id={candidate_id}&cycle=2018&api_key={api_key}",
"/schedules/schedule_a/by_state/by_candidate/?candidate_id={candidate_id}&cycle=2018&api_key={api_key}",
"/candidates/totals/?api_key={api_key}",
"/schedules/schedule_a/by_state/totals/?api_key={api_key}",
"/communication_costs/by_candidate/?api_key={api_key}&candidate_id={candidate_id}",
"/communication_costs/totals/by_candidate?api_key={api_key}",
"/electioneering/?api_key={api_key}",
"/electioneering/aggregates/?api_key={api_key}",
"/electioneering/by_candidate/?api_key={api_key}&candidate_id={candidate_id}",
"/electioneering/totals/by_candidate?api_key={api_key}&candidate_id={candidate_id}",
"/committee/{committee_id}/filings/?api_key={api_key}",
"/candidate/{candidate_id}/filings/?api_key={api_key}",
"/efile/reports/house-senate/?api_key={api_key}",
"/efile/reports/presidential/?api_key={api_key}",
"/efile/reports/pac-party/?api_key={api_key}",
"/filings/?api_key={api_key}", # this one is also shooting for trailing slash issue
"/candidates/totals/by_office/?api_key={api_key}",
"/candidates/totals/by_office/by_party/?api_key={api_key}",
]
@click.command()
@click.option(
"--server",
default="https://fec-dev-api.app.cloud.gov",
help="server to check with.",
)
@click.option(
"--api_key",
default=lambda: os.environ.get("FEC_API_KEY", ""),
help="an api_key is needed for testing.",
)
def check_endpoints(server, api_key):
"""Simple script to check all endpoints status quickly."""
for endp in endpoints:
r = requests.get(
(server + "/v1" + endp).format(
api_key=api_key,
committee_id=COMMITTEE_ID,
candidate_id=CANDIDATE_ID,
committee_type=COMMITTEE_TYPE,
sub_id=SUB_ID,
)
)
if r.status_code == 200:
print("{}: ok".format(endp))
else:
print("******{}: not working. Status: {}".format(endp, r.status_code))
if __name__ == "__main__":
check_endpoints()