-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-pa.py
executable file
·89 lines (79 loc) · 2.07 KB
/
test-pa.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
#!/usr/bin/env python
import argparse
import datetime
import json
import logging
import sys
import ovrlib.pa
logging.basicConfig(level=logging.DEBUG)
parser = argparse.ArgumentParser()
parser.add_argument("api_key", help="API key provided from PA")
parser.add_argument(
"--with-dl", help="pass a PennDOT DL", action="store_true", required=False
)
parser.add_argument(
"--with-ssn", help="pass last 4 of SSN", action="store_true", required=False
)
parser.add_argument("--signature", help="signature file", required=False)
parser.add_argument(
"--election-info",
help="fetch upcoming election info",
action="store_true",
required=False,
)
parser.add_argument(
"--get-constants",
help="print all constants fetched from API",
action="store_true",
required=False,
)
parser.add_argument(
"--print-constants-code",
help="print API constants (e.g., to update code)",
action="store_true",
required=False,
)
args = parser.parse_args()
session = ovrlib.pa.PAOVRSession(api_key=args.api_key, staging=True)
if args.get_constants:
r = session.fetch_constants()
print(json.dumps(r, indent=4))
sys.exit()
if args.print_constants_code:
session.print_constants()
sys.exit()
if args.election_info:
print(session.get_election_info())
sys.exit()
# test registration
sig = None
sig_type = None
if args.signature:
with open(args.signature, "rb") as f:
sig = f.read()
sig_type = args.signature.split(".")[-1]
req = ovrlib.pa.PAOVRRequest(
first_name="Sally",
last_name="Penndot",
suffix="XIV",
date_of_birth=datetime.date(year=1944, month=5, day=2),
address1="123 A St",
city="Clarion",
zipcode="16214",
county="Clarion",
gender="female",
party="Democrat",
federal_voter=True,
united_states_citizen=True,
eighteen_on_election_day=True,
declaration=True,
signature=sig,
signature_type=sig_type,
)
if args.with_dl:
req.dl_number = "99007069"
if args.with_ssn:
req.ssn4 = "1234"
print(req.to_request_body())
response = session.register(req)
print(response)