-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
60 lines (43 loc) · 1.47 KB
/
script.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
import os, sys
from random import shuffle
def giveQuestions():
a = []
for x in sprgGenerator(os.listdir("./sporgsmaal/")):
a.append(x)
shuffle(a)
if len(a) < 40:
return a
else:
return a[:40]
def readQuestion(question): #returns question in latexform according to example in tex folder.
stream = open(question, "r" , encoding="utf-8")
lines = stream.readlines()
string = "\question \\textbf{" + lines[0] + "}\\\\\n"
if len(lines) == 2:
string = string + "\correctchoice \\underline{\phantom{" + lines[1][1:] + "}}\\\\\n"
else:
for line in lines[1:]:
if line[0] == "#":
string = string + "\correctchoice $\\Box$ " + line[1:] + "\\\\\n"
else:
string = string + "\choice $\\Box$ " + line + "\\\\\n"
stream.close()
return string
def sprgGenerator(liste):
for name in liste:
if name[-5:] == ".sprg": yield name
def writeTex(name):
f = open(name, "w+" , encoding="utf-8")
header = open("./tex/header.tex" , "r" , encoding="utf-8")
for line in header.readlines():
f.write(line)
header.close()
f.write("\\begin{document}\n \\begin{questions}\n")
questions = giveQuestions()
for question in questions:
q = readQuestion("./sporgsmaal/" + question)
f.write(q + "\n\n")
f.write("\end{questions}\n \end{document}")
f.close()
if __name__ == "__main__":
writeTex(sys.argv[1])