diff --git a/tools/package-puzzles.py b/tools/package-puzzles.py index 90b248b..f852d6d 100755 --- a/tools/package-puzzles.py +++ b/tools/package-puzzles.py @@ -31,6 +31,57 @@ def write_kv_pairs(ziphandle, filename, kv): filehandle.write("%s: %s%s" % (key, kv[key], os.linesep)) filehandle.seek(0) ziphandle.writestr(filename, filehandle.read()) + +def escape(s): + return s.replace('&', '&').replace('<', '<').replace('>', '>') + +def generate_html(ziphandle, puzzle, puzzledir, category, points, author, files): + html_content = io.StringIO() + file_content = io.StringIO() + if files: + file_content.write( +'''
+

Associated files:

+ +
+''') + + html_content.write( +''' + + + + + {category} {points} + + + +

{category} for {points} points

+
+{body}
+{file_content}
+
+ + +
Team hash:
+
Answer:
+ +
+
+
Puzzle by {author}
+
+ Los Alamos National Laboratory + US Department Of Energy + Sandia National Laboratories +
+ +'''.format(category=category, points=points, body=puzzle.html_body(), file_content=file_content.getvalue(), author=author)) + ziphandle.writestr(os.path.join(puzzledir, 'index.html'), html_content.getvalue()) def build_category(categorydir, outdir): zipfileraw = tempfile.NamedTemporaryFile(delete=False) @@ -88,6 +139,7 @@ def build_category(categorydir, outdir): } puzzlejson = json.dumps(puzzledict) zf.writestr(os.path.join(puzzledir, 'puzzle.json'), puzzlejson) + generate_html(zf, puzzle, puzzledir, categoryname, puzzle.points, puzzle.author, files) write_kv_pairs(zf, 'map.txt', mapping) write_kv_pairs(zf, 'answers.txt', answers)