-
Notifications
You must be signed in to change notification settings - Fork 1
/
roster_parser.py
56 lines (44 loc) · 1.5 KB
/
roster_parser.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
from csv import DictReader
import io
student_row_keys = [
('student_id','SEPID'),
('last_name','Last Name'),
('first_name','First Name'),
('dec','DEC'),
('parent_name','Parent/Legal Guardian'),
('parent_email','ECOT Parent/Legal Guardian Email'),
('grade', 'Gr'),
('phone_number',('Home','Parent Cell','Student Cell')),
('status','Stat'),
('enr_date','Enr'),
('r_score_in','OGT Rdg'),
('w_score_in','OGT Wri')]
def parse_roster(file):
file = io.StringIO(unicode(file.read()),newline=None)
#skip initial lines
file.readline()
file.readline()
file.readline()
file.readline()
reader = DictReader(file)
data = []
for line in reader:
row = {}
#print "test: ",line
for my_key,their_key in student_row_keys:
if my_key == "phone_number":
home = line[their_key[0]]
p_cell = line[their_key[1]]
s_cell = line[their_key[2]]
if home: row[my_key] = home
elif p_cell: row[my_key] = p_cell
elif s_cell: row[my_key] = s_cell
elif my_key == "dec":
row[my_key] = bool(line[their_key])
else:
row[my_key] = line[their_key]
data.append(row)
return data
if __name__=="__main__":
roster = open('K12_CourseRosterOGT.csv','rU')
print parse_roster(roster)