-
Notifications
You must be signed in to change notification settings - Fork 0
/
students.py
executable file
·50 lines (41 loc) · 1.05 KB
/
students.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
#!/usr/bin/env python3
import argparse
import functools
from configparser import ConfigParser
from ocflib.infra import db
from ocflib.misc.mail import email_for_user
parser = argparse.ArgumentParser(
description='Get emails for decal students',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
'-c',
'--config',
default='/etc/decal_mysql.conf',
help='Config file to sql creds read from.',
)
parser.add_argument(
'-t',
'--track',
default='%',
help='Which track to dump emails from (basic, advanced).',
)
args = parser.parse_args()
config = ConfigParser()
config.read(args.config)
user = config.get('mysql', 'user')
pw = config.get('mysql', 'password')
dbname = config.get('mysql', 'db')
conn = functools.partial(
db.get_connection,
user=user,
password=pw,
db=dbname,
)
with conn() as c:
c.execute(
'SELECT `username` FROM `students` WHERE `track` LIKE %s',
(args.track,)
)
for student in c.fetchall():
print(email_for_user(student['username']))