-
Notifications
You must be signed in to change notification settings - Fork 7
/
generate-reminder-urls.py
54 lines (45 loc) · 1.45 KB
/
generate-reminder-urls.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
"""Script to convert election id and email address(es) to reminder Email URL.
The desired output is a list of URLs for someone to use to send individual
emails.
"""
import argparse
import collections
import csv
import uuid
Voter = collections.namedtuple('Voter', 'id, email, name')
def create_parser():
"""Create an argument parser."""
parser = argparse.ArgumentParser()
parser.add_argument(
'--election', dest='election_id',
type=uuid.UUID,
help='Election UUID',
)
parser.add_argument(
'--voter-file', dest='voter_file',
type=argparse.FileType('r'),
help='List of voters in Helios CSV bulk upload format',
)
parser.add_argument(
'emails',
nargs=argparse.REMAINDER,
help='email addresses of voters',
)
return parser
def main():
"""Generate the URLs."""
parser = create_parser()
args = parser.parse_args()
helios_list = csv.reader(args.voter_file, delimiter=',')
voters_list = [Voter(*row) for row in helios_list]
voters_by_email = {voter.email: voter for voter in voters_list}
election_id = str(args.election_id)
for email in args.emails:
try:
voter = voters_by_email[email]
except KeyError:
print(f'No voter with email "{email}"')
else:
print(f'https://vote.heliosvoting.org/helios/elections/{election_id}/voters/email?voter_id={voter.id}')
if __name__ == '__main__':
main()