-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsttx.py
104 lines (71 loc) · 2.66 KB
/
sttx.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
import sys
# Try to import pyquery. If the module is not found, print an error and quit program
try:
from lxml import etree
except:
print("\nError. The 'lxml' module was not found on your system.\nInstall it by running 'pip install lxml'")
sys.exit(5)
root = etree.Element("timetable")
def saveLecture(elem, l):
newLecture = etree.SubElement(elem, 'lecture')
day = etree.SubElement(newLecture, "day")
day.text = l.day
start = etree.SubElement(newLecture, "start")
start.text = str(l.start)
finish = etree.SubElement(newLecture, "finish")
finish.text = str(l.finish)
def saveClass(c):
newClass = etree.SubElement(root, 'class')
newClass.set("subject", c.subject.name)
comp = etree.SubElement(newClass, "comp")
comp.text = c.comp
descr = etree.SubElement(newClass, "descr")
descr.text = c.descr
include = etree.SubElement(newClass, "include")
include.text = c.getInclude()
for l in c.lectures:
saveLecture(newClass, l)
def saveColor(elem, t, tp, p, ot):
color_t = etree.SubElement(elem, 't')
color_t.text = str(int(t, 16) - 1)
color_tp = etree.SubElement(elem, 'tp')
color_tp.text = str(int(tp, 16) - 1)
color_p = etree.SubElement(elem, 'p')
color_p.text = str(int(p, 16) - 1)
color_ot = etree.SubElement(elem, 'ot')
color_ot.text = str(int(ot, 16) - 1)
def getSubjects(classes):
subjects = []
for c in classes:
if not c.subject in subjects:
subjects.append(c.subject)
return subjects
def export(name, classes):
if ".sttx" not in name:
name = name + ".sttx"
fout = open(name, 'w')
for s in getSubjects(classes):
newSubject = etree.SubElement(root, "subject")
newSubject.text = s.name
for c in classes:
saveClass(c)
colormode = etree.SubElement(root, "colormode")
colormode.text = "RELATIVE"
allcolors = etree.SubElement(root, "allcolors")
saveColor(allcolors, "000000", "000000", "000000", "000000")
for s in getSubjects(classes):
newColor = etree.SubElement(root, "colormapping")
subject = etree.SubElement(newColor, "subject")
subject.text = s.name
saveColor(newColor, s.color, s.color, s.color, "000000")
overlapping = etree.SubElement(root, "overlapping")
mode = etree.SubElement(overlapping, "mode")
mode.text = "NONE"
count = etree.SubElement(overlapping, "count")
count.text = "null"
time = etree.SubElement(overlapping, "time")
time.text = "null"
fout.write(etree.tostring(root, xml_declaration=True, encoding="utf-8", pretty_print=True).decode('utf-8'))
fout.close()
if __name__ == "__main__":
main()