X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=html_generator.py;h=b944391ed2cd15745f57b1c29ac563d889b2893e;hb=88cc255b97357ff671194816186c88b6b42eaccf;hp=e75f14836921015be8247fa1ea5d25a153d12b71;hpb=5eb6c0e95cb218e6aa7b7c61613e9a73d526549b;p=turbot-web
diff --git a/html_generator.py b/html_generator.py
index e75f148..b944391 100644
--- a/html_generator.py
+++ b/html_generator.py
@@ -14,7 +14,9 @@ that would be great
Requires sorttable.js, which should be included
"""
+import boto3
from boto3.dynamodb.conditions import Key
+import re
website = "https://halibut.cworth.org/"
#change this if we're using AWS or some other subdomain instead
@@ -24,14 +26,14 @@ def channel_url(channel_id):
return "https://halibutthatbass.slack.com/archives/{}".format(channel_id)
-def find_hunt_for_hunt_id(turb, hunt_id):
+def find_hunt_for_hunt_id(table, hunt_id):
"""Given a hunt ID find the database item for that hunt
Returns None if hunt ID is not found, otherwise a
dictionary with all fields from the hunt's row in the table,
(channel_id, active, hunt_id, name, url, sheet_url, etc.).
"""
- response = turb.table.get_item(
+ response = table.get_item(
Key={
'hunt_id': hunt_id,
'SK': 'hunt-{}'.format(hunt_id)
@@ -42,10 +44,10 @@ def find_hunt_for_hunt_id(turb, hunt_id):
else:
return None
-def hunt_puzzles_for_hunt_id(turb, hunt_id):
+def hunt_puzzles_for_hunt_id(table, hunt_id):
"""Return all puzzles that belong to the given hunt_id"""
- response = turb.table.query(
+ response = table.query(
KeyConditionExpression=(
Key('hunt_id').eq(hunt_id) &
Key('SK').begins_with('puzzle-')
@@ -63,15 +65,17 @@ def link(lin, text):
#internal links, doesn't open new tab
return '{}'.format(lin, text)
-def hunt_info(turb, hunt):
+def hunt_info(table, hunt_id):
"""
Retrieves list of rounds, puzzles for the given hunt
"""
+
+ hunt = find_hunt_for_hunt_id(table, hunt_id)
+
name = hunt["name"]
- hunt_id = hunt["hunt_id"]
channel_id = hunt["channel_id"]
- puzzles = hunt_puzzles_for_hunt_id(turb, hunt_id)
+ puzzles = hunt_puzzles_for_hunt_id(table, hunt_id)
rounds = set()
for puzzle in puzzles:
@@ -242,22 +246,22 @@ def round_overview(rnd, puzzles):
if puzzle['status'] == 'solved':
puzzle_list += [ '
\n',
' {} | \n'.format(elink(slack_url, puzzle['name']+meta)),
- ' {} | \n'.format(elink(puzzle['url'], 'Puzzle')),
+ ' {} | \n'.format(elink(puzzle.get('url',''), 'Puzzle')),
' {} | \n'.format(elink(puzzle['sheet_url'], 'Sheet')),
' {} | \n'.format(link(website + "_".join(puzzle['name'].split()) + '.html', 'Overview')),
' {} | \n'.format(puzzle['solution']),
# ' | \n',
- ' {} | \n'.format("".join(puzzle['tags'])),
+ ' {} | \n'.format("".join(puzzle.get('tags',[]))),
'
\n']
else:
puzzle_list += [ ' \n',
' {} | \n'.format(elink(slack_url, puzzle['name']+meta)),
- ' {} | \n'.format(elink(puzzle['url'], 'Puzzle')),
+ ' {} | \n'.format(elink(puzzle.get('url',''), 'Puzzle')),
' {} | \n'.format(elink(puzzle['sheet_url'], 'Sheet')),
' {} | \n'.format(link(website + "_".join(puzzle['name'].split()) + '.html', 'Overview')),
' | \n',
# ' | \n',
- ' {} | \n'.format(" ".join(puzzle['tags'])),
+ ' {} | \n'.format(" ".join(puzzle.get('tags',[]))),
'
\n']
end = [' \n',
' \n',
@@ -281,7 +285,10 @@ def puzzle_overview(puzzle):
else:
meta = ''
slack_url = channel_url(puzzle['channel_id'])
- round_url = [link(website + "_".join(rnd.split()) + "_round.html", rnd) for rnd in puzzle['rounds']]
+ if 'rounds' in puzzle:
+ round_url = [link(website + "_".join(rnd.split()) + "_round.html", rnd) for rnd in puzzle['rounds']]
+ else:
+ round_url = ''
if puzzle['status'] == 'solved':
solution = puzzle['solution']
status = 'solved'
@@ -304,7 +311,7 @@ def puzzle_overview(puzzle):
' \n',
' \n',
' {} | \n'.format(elink(slack_url, 'Channel')), #slack channel
- ' {} | \n'.format(elink(puzzle['url'], 'Puzzle')),
+ ' {} | \n'.format(elink(puzzle.get('url',''), 'Puzzle')),
' {} | \n'.format(elink(puzzle['sheet_url'], 'Sheet')),
' Additional Resources | \n',
'
\n',
@@ -312,7 +319,7 @@ def puzzle_overview(puzzle):
' \n',
' \n',
' Round(s): {} | \n'.format(" ".join(round_url)), #round page on our site
- ' Tags: {} | \n'.format(" ".join(puzzle['tags'])), #add tags
+ ' Tags: {} | \n'.format(" ".join(puzzle.get('tags',[]))), #add tags
'
\n',
' \n',
' Answer: {} | \n'.format(solution),
@@ -323,7 +330,8 @@ def puzzle_overview(puzzle):
'\n',
'