summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2015-11-05 14:51:03 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2015-11-05 14:51:03 +0100
commit9b0915cb2ac613d2da04381772f2bf840f99068b (patch)
tree962301d2e0dc79fcb95fc286d2c234ad82df56fa /scripts
parent08519a9884977b5a52bcac85ab24ff04f5988528 (diff)
Add a script to generate HTML with problem description
Diffstat (limited to 'scripts')
-rw-r--r--scripts/problem_html.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/scripts/problem_html.py b/scripts/problem_html.py
new file mode 100644
index 0000000..4d71b18
--- /dev/null
+++ b/scripts/problem_html.py
@@ -0,0 +1,78 @@
+#!/usr/bin/python
+
+import sys
+
+from server.problems import load_problem
+
+if len(sys.argv) < 5:
+ sys.stderr.write('usage: {} programming_language group problem language\n'.format(sys.argv[0]))
+ sys.exit(1)
+language, group, problem, tail = sys.argv[1:]
+mod = load_problem(language, group, problem, tail)
+
+print('''\
+<DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>Problem</title>
+ <style>
+h2 {
+ margin-top: 1em;
+ margin-bottom: 0.5em;
+}
+h3 {
+ margin-bottom: 0.3em;
+ margin-top: 0.2em;
+}
+p {
+ margin-bottom: 0.2em;
+ margin-top: 0;
+}
+section {
+ margin-bottom: 1.5em;
+}
+ </style>
+ </head>
+ <body>''')
+
+print('<h1>{}</h1>'.format(mod.name))
+print('{}'.format(mod.description))
+
+print('<section>')
+print('<h2>Plan</h2>')
+for n, plan in enumerate(mod.plan):
+ print('<section>')
+ print('<h3>Plan #{}</h3>'.format(n))
+ if isinstance(plan, list):
+ for i, p_part in enumerate(plan):
+ if isinstance(p_part, dict):
+ p_part = p_part['message']
+ print(p_part)
+ if i < len(plan)-1:
+ print('<hr />')
+ else:
+ print(plan)
+ print('</section>')
+print('</section>')
+
+print('<section>')
+print('<h2>Hints</h2>')
+for id, hint in sorted(mod.hint.items()):
+ print('<section>')
+ print('<h3>{}</h3>'.format(id))
+ if isinstance(hint, list):
+ for i, hint_part in enumerate(hint):
+ if isinstance(hint_part, dict):
+ hint_part = hint_part['message']
+ print(hint_part)
+ if i < len(hint)-1:
+ print('<hr />')
+ else:
+ print(hint)
+ print('</section>')
+print('</section>')
+
+print('''\
+ </body>
+</html>''')