-
Notifications
You must be signed in to change notification settings - Fork 0
/
Blink2Webwork_diff.py
68 lines (50 loc) · 2.36 KB
/
Blink2Webwork_diff.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
###### Written by Ning Ma ######
###### 9.24.2015 ######
import sys
from sets import Set
"""
Take five arguments representing file names: writeFile, oldEnrollFile, oldWaitListFile, newEnrollFile, newWaitListFile. The file inputs MUST following the above order.
All the files are in .tsv format.
Subtract students who are new to the oldEnrollFile (not from oldWaitListFile) or new to the oldWaitListFile. Write the informatio of these students to the writeFile and export as .lst format.
"""
#Get PID sets from old enrollment and old waiting list files.
#The first argument must be the enrollment .lst file and the second file
#must be the waiting list .lst file
def getPIDSet(enrollFile, waitListFile):
enrollPID = Set()
waitListPID = Set()
for i in range(4):
enrollFile.readline()
waitListFile.readline()
for line in enrollFile.readlines():
SecID, PID, Student, Credits, College, Major, Level, Email = line.strip().split('\t')
enrollPID.add(PID);
for line in waitListFile.readlines():
SecID, PID, Student, College, Major, Level, Date, Time, Email= line.strip().split('\t')
waitListPID.add(PID)
return [enrollPID, waitListPID]
outputFile = open(sys.argv[1], "a");
oldEnroll = open(sys.argv[2],'r');
oldWaitList = open(sys.argv[3],'r');
newEnroll = open(sys.argv[4],'r');
newWaitList = open(sys.argv[5], 'r');
[oldEnrollPID, oldWaitListPID] = getPIDSet(oldEnroll, oldWaitList)
for i in range(4):
newEnroll.readline()
newWaitList.readline()
#add new enrolled student (not from old waiting list) to the outputFIle
for line in newEnroll.readlines():
SecID, PID, Student, Credits, College, Major, Level, Email = line.strip().split('\t')
Last, First = Student.split(',');
Email = Email.strip();
userID, emailDomain = Email.split('@');
if (PID not in oldEnrollPID) and (PID not in oldWaitListPID):
outputFile.write(','.join([PID,Last,First,'','',SecID,'',Email,userID]) + '\n')
#add new waiting list student to the outputFile
for line in newWaitList.readlines():
SecID, PID, Student, College, Major, Level, Date, Time, Email= line.strip().split('\t')
Last, First = Student.split(',');
Email = Email.strip();
userID, emailDomain = Email.split('@');
if PID not in oldWaitListPID:
outputFile.write(','.join([PID,Last,First,'','',SecID,'',Email,userID]) + '\n')