forked from drchrisgreen/Englaid_code_bits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
startenddates.py
48 lines (43 loc) · 1.25 KB
/
startenddates.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
import csv
def getdates(infile, outfile):
xmlin = open (infile, 'r')
csvout = csv.writer(open(outfile, 'wb'), delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
header = ['MonUID','term','startdate','enddate']
csvout.writerow(header)
processing = 0
for line in xmlin:
if processing == 0 and '<xmlzEngLaID_MonType>' in line:
processing = 1
outlist = []
elif processing == 0:
continue
elif '<xmlzEngLaID_Evidence>' in line:
processing = 0
elif '</xmlzEngLaID_MonType>' in line:
if len(outlist) == 2:
outlist.append('')
outlist.append('')
elif len(outlist) == 3:
outlist.append('')
csvout.writerow(outlist)
outlist = []
elif '<MonUID>' in line:
pos1 = line.find('>') + 1
pos2 = pos1 + line[pos1:].find('<')
tempstr = line[pos1:pos2]
outlist.append(tempstr)
elif '<Term>' in line:
pos1 = line.find('>') + 1
pos2 = pos1 + line[pos1:].find('<')
tempstr = line[pos1:pos2]
outlist.append(tempstr)
elif '<YearFrom>' in line:
pos1 = line.find('>') + 1
pos2 = pos1 + line[pos1:].find('<')
tempstr = line[pos1:pos2]
outlist.append(tempstr)
elif '<YearTo>' in line:
pos1 = line.find('>') + 1
pos2 = pos1 + line[pos1:].find('<')
tempstr = line[pos1:pos2]
outlist.append(tempstr)