forked from scriptythekid/lazystudent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_lazyoutput.py
120 lines (97 loc) · 3.55 KB
/
parse_lazyoutput.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import sys
import os
from BeautifulSoup import BeautifulSoup
import codecs
from mako.template import Template
import re
try:
semester = 'SS' if sys.argv[1].upper() == 'SS' else 'WS'
except Exception:
print ""
print " ","usage:"
print ""
print " ",sys.argv[0],"<semester>"
print ""
print " ",sys.argv[0],"WS"
print " ",sys.argv[0],"SS"
print ""
sys.exit(1)
lvas=[]
for x in os.listdir('output/%s' % semester):
fd=codecs.open(os.path.join('output',semester,x), encoding='utf-8')
s = BeautifulSoup(fd.read())
fd.close()
lva={'lva_info':None,
'personlink':None,
'person':None,
'descr':None,
'nachweis':None,
'ort':None,
'anmerkungen':None,
'has_DK':None,
'ects':None,
'wstd':None,
'lvanr':None,
'lvatype':None,
'semester':None,
'abschnitt':'not implemented yet',
}
lva['has_DK'] = False
hasinfo = s.findAll(name='h1')
if hasinfo:
lva['lva_info'] = hasinfo[0].text
#infos = [x.replace('(','').replace(')','').strip() for x in re.search('\([a-zA-Z0- .\/\)]*',lva['lva_info']).group(0).split('/')]
infostr = lva['lva_info']
infostr = infostr[infostr.rfind('('):]
infos = [x.strip() for x in infostr.split('(')[1].split(')')[0].split('/')]
lva['ects'] = re.search('[0-9,]+ ECTS',lva['lva_info']).group(0).replace('ECTS','').strip()
lva['wstd'] = re.search('[0-9]+ WStd',lva['lva_info']).group(0).replace('WStd','').strip()
lva['lvatype'] = infos[3]
lva['lvanr'] = infos[4]
lva['semester'] = infos[0]
hasperson = s.findAll(name='h2')
if hasperson:
lva['personlink'] = hasperson[0].next.next
lva['person'] = unicode(s.findAll(name='h2')[0].next.next.text)
hasdescr = s.find(text="Themenstellung der Lehrveranstaltung")
if hasdescr:
lva['descr'] = hasdescr.findNext(name='tr').text
hasnachweis = s.find(text="Nachweis der erworbenen Kompetenzen durch:")
if hasnachweis:
lva['nachweis'] = hasnachweis.findNext(name='tr').text
hasort = s.find(text="Angaben zu Ort und Zeit der Lehrveranstaltung:")
if hasort:
lva['ort'] = hasort.findNext(name='tr').text
hasanmerk = s.find(text="Anmerkungen:")
if hasanmerk:
lva['anmerkungen'] = hasanmerk.findNext(name='tr').text
hasstudiplatz = s.find(text="Studienplanzuordnungen:")
if hasstudiplatz:
studieslist = [x.text for x in hasstudiplatz.findAllNext(name='tr')]
studiestext = os.linesep.join(studieslist)
lva['has_DK'] = 'digitale kunst' in studiestext.lower()
lvas.append(lva)
#dev h4x
#if len(sys.argv) > 2 and sys.argv[2] and len(lvas) > 10: break
myt= Template(filename='index_template.mako', output_encoding='utf-8', input_encoding='utf-8', default_filters=['decode.utf8'], encoding_errors='replace')
htmlout = myt.render_unicode(data=lvas)
outfilename=os.path.join('output',semester,'index.html')
fd = codecs.open(outfilename, 'w', encoding='utf-8')
fd.write(htmlout)
fd.close()
print "done"
print "output written to",outfilename