website = "https://halibut.cworth.org/"
#change this if we're using AWS or some other subdomain instead
+def filename_from_name(name):
+ """Returns a string derived from name, but with all spaces and slashes
+ replaced with underscores, (for making a clean filename)"""
+ return re.sub(r'[ /]', '_', name)
+
def channel_url(channel_id):
"""Given a channel ID, return the URL for that channel."""
expanding += [
' <div id="b{}" class="containerTab {}" style="display:none;">\n'.format(i, status),
' <span onclick="this.parentElement.style.display=\'none\'" class="closebtn">x</span>\n',
- ' <h2>{}</h2>\n'.format(link(website + "_".join(rnd.split()) + "_round.html", rnd)),
+ ' <h2>{}</h2>\n'.format(link(website + filename_from_name(rnd) + "_round.html", rnd)),
' <table class="sortable">\n',
' <tr>\n',
' <th><u>Puzzle</u></th>\n',
meta = ''
if puzzle['status'] == 'solved':
expanding += [' <tr class=\'solved\';>\n',
- ' <td>{}</td>\n'.format(link(website + "_".join(puzzle['name'].split()) + ".html", puzzle['name']+meta)),
+ ' <td>{}</td>\n'.format(link(website + filename_from_name(puzzle['name']) + ".html", puzzle['name']+meta)),
' <td>{}</td>\n'.format(puzzle['solution']),
' </tr>\n']
else:
expanding += [' <tr class=\'unsolved\';>\n',
- ' <td><b>{}</b></td>\n'.format(link(website + "_".join(puzzle['name'].split()) + ".html", puzzle['name']+meta)),
+ ' <td><b>{}</b></td>\n'.format(link(website + filename_from_name(puzzle['name']) + ".html", puzzle['name']+meta)),
' <td></td>\n',
' </tr>\n']
expanding.append(' </table>\n')
' <td>{}</td>\n'.format(elink(slack_url, puzzle['name']+meta)),
' <td>{}</td>\n'.format(elink(puzzle.get('url',''), 'Puzzle')),
' <td>{}</td>\n'.format(elink(puzzle['sheet_url'], 'Sheet')),
- ' <td>{}</td>\n'.format(link(website + "_".join(puzzle['name'].split()) + '.html', 'Overview')),
+ ' <td>{}</td>\n'.format(link(website + filename_from_name(puzzle['name']) + '.html', 'Overview')),
' <td>{}</td>\n'.format(puzzle['solution']),
# ' <td></td>\n',
' <td>{}</td>\n'.format("".join(puzzle.get('tags',[]))),
' <td><b>{}</b></td>\n'.format(elink(slack_url, puzzle['name']+meta)),
' <td>{}</td>\n'.format(elink(puzzle.get('url',''), 'Puzzle')),
' <td>{}</td>\n'.format(elink(puzzle['sheet_url'], 'Sheet')),
- ' <td>{}</td>\n'.format(link(website + "_".join(puzzle['name'].split()) + '.html', 'Overview')),
+ ' <td>{}</td>\n'.format(link(website + filename_from_name(puzzle['name']) + '.html', 'Overview')),
' <td></td>\n',
# ' <td></td>\n',
' <td>{}</td>\n'.format(" ".join(puzzle.get('tags',[]))),
' </body>\n',
'</html>\n']
html = start + puzzle_list + end
- file = "{}_round.html".format('_'.join(rnd.split()))
+ file = "{}_round.html".format(filename_from_name(rnd))
f = open(file, "w")
for line in html:
f.write(line)
meta = ''
slack_url = channel_url(puzzle['channel_id'])
if 'rounds' in puzzle:
- round_url = [link(website + "_".join(rnd.split()) + "_round.html", rnd) for rnd in puzzle['rounds']]
+ round_url = [link(website + filename_from_name(rnd) + "_round.html", rnd) for rnd in puzzle['rounds']]
else:
round_url = ''
if puzzle['status'] == 'solved':
'\n',
'</body>\n',
'</html>\n']
- # Replace all spaces and slashes in the name with underscores
- underscored = re.sub(r'[ /]', '_', name)
- file = "{}.html".format(underscored)
+ file = "{}.html".format(filename_from_name(name))
f = open(file, "w")
for line in html:
f.write(line)
meta = ''
slack_url = channel_url(puzzle['channel_id'])
if 'rounds' in puzzle:
- round_url = link(website + "_".join(rnd.split()) + "_round.html", puzzle['rounds'][0])
+ round_url = link(website + filename_from_name(rnd) + "_round.html", puzzle['rounds'][0])
else:
round_url = ''
#assuming one round per puzzle for now
' <td>{}</td>\n'.format(elink(slack_url, puzzle['name']+meta)),
' <td>{}</td>\n'.format(elink(puzzle.get('url',''), 'Puzzle')),
' <td>{}</td>\n'.format(elink(puzzle['sheet_url'], 'Sheet')),
- ' <td>{}</td>\n'.format(link(website + "_".join(puzzle['name'].split()) + '.html', 'Overview')),
+ ' <td>{}</td>\n'.format(link(website + filename_from_name(puzzle['name']) + '.html', 'Overview')),
' <td>{}</td>\n'.format(puzzle['solution']),
' <td>{}</td>\n'.format(round_url),
' <td>{}</td>\n'.format("".join(puzzle.get('tags',[]))),
meta = ''
slack_url = channel_url(puzzle['channel_id'])
if 'rounds' in puzzle:
- round_url = link(website + "_".join(rnd.split()) + "_round.html", puzzle['rounds'][0])
+ round_url = link(website + filename_from_name(rnd) + "_round.html", puzzle['rounds'][0])
else:
round_url = ''
#assuming one round per puzzle for now
' <td>{}</td>\n'.format(elink(slack_url, puzzle['name']+meta)),
' <td>{}</td>\n'.format(elink(puzzle.get('url',''), 'Puzzle')),
' <td>{}</td>\n'.format(elink(puzzle['sheet_url'], 'Sheet')),
- ' <td>{}</td>\n'.format(link(website + "_".join(puzzle['name'].split()) + '.html', 'Overview')),
+ ' <td>{}</td>\n'.format(link(website + filename_from_name(puzzle['name']) + '.html', 'Overview')),
' <td></td>\n',
' <td>{}</td>\n'.format(round_url),
' <td>{}</td>\n'.format("".join(puzzle.get('tags',[]))),