-
Notifications
You must be signed in to change notification settings - Fork 0
/
retrieve.py
68 lines (59 loc) · 1.66 KB
/
retrieve.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
#this function gets rid of all the lines that are column headings and my ID at the top of the orignal .txt file RUN FIRST
#outputs cleanedClasses.txt
def newFile(rawClassesFile):
f = open(rawClassesFile,'r')
fw = open('cleanedClasses.txt','w')
for lines in f:
#print lines[:2]
#print "\n"
if lines[:3] == "SR\t" or lines[:2] == "C\t" or lines[:3] =="NR\t":
fw.write(lines)
#print ("yes")
fw.close()
f.close()
#this function gets rid of the columns that don't matter to us, leaves only the necessary info we will print writes TO necessaryClasses.txt
def readToVariables():
f = open('cleanedClasses.txt','r')
fw = open('necessaryClasses.txt','w')
for lines in f:
lInfo=lines.split("\t")
fw.write(lInfo[7])
fw.write("\t")
fw.write(lInfo[8])
fw.write("\t")
fw.write(lInfo[9])
fw.write("\t")
fw.write(lInfo[19])
fw.write("\t")
fw.write(lInfo[21])
fw.write("\t")
fw.write(lInfo[22])
fw.close()
f.close()
if __name__ == "__main__":
readToVariables()
# . any char
# \w word char
# \d digit
# \s whitespace
# \S nonWhitespace
# + 1 or more
# * 0 or more
# re.findall(r'\d\d\d', string)
#this function will not be used, but will remain here for reference of REGEX
def read():
import re
lResults = []
f = open('springClasses.txt','r')
fw = open('outputClasses.txt','w')
i=0
for lines in f:
i=i+1
print i
mMatch = re.search('.+\t.+\t.+\t.+\t.+\t.+\t.+\t(.+)\t(.+)\t(.+)\t.+\t.+\t.+\t.+\t.+\t.+\t.+\t.+\t.+\t(.+)\t.+\t(.+)\t.+',lines)
if mMatch:
lResults.append(mMatch.group)
print mMatch.group
fw.write(lResults)
fw.close()
f.close()