Goal: to produce html files for the e2 microquests using only barebones info from a csv file.
Solution: Python
Saving this here in case I need to purge the computer in March and/or if I need to pass the baton and/or if someone else needs it
File: wordenchiladas.py
Requires: Python 3.x; markdown package
Usage: Just run python wordenchiladas.py
# To quickly generate html files for future word enchiladas
#
# You'll need:
# 1. a Markdown-formatted template ('template.txt')
# 2. a csv ('wordenchiladas.csv') with:
# - season number
# - episode number
# - theme
# - length (not used yet)
# - YYYY-MM-DD start date
# - YYYY-MM-DD end date
# - Notes (optional)
#
# The end product is a lot of barebones html files, correctly enumerated
# with proper theme---encoded with rot13---, suggested nodetype, start and
# end dates.
#
# If this is for E2, remember that links there work with square brackets,
# so the template must have links like this:
#
# > This is an \[target\|example link\]
#
# The "length" is a feature yet to be implemented. The idea is to have
# Quests with different parameters (different week days, duration, etc)
# so that you can just take the start ISO date and length and generate the
# appropriate end times with `datetime` and `timedelta`. **Ask in e2
# what other times are good for enchiladas**.
import markdown
import csv
from datetime import date
def rot13(intext):
# Barebones rot13 encoder/decoder. Ignores punctuation. Returns uppercase
# because I can't be bothered to
abc = "abcdefghijklmnopqrstuvwxyz"
cba = "nopqrstuvwxyzabcdefghijklm"
secret = ""
for i in intext.lower():
if i in abc:
secret += cba[abc.index(i)]
else:
secret += i
return(secret.upper())
with open('wordenchiladas.csv', newline='', encoding="utf-8") as csvfile:
# Doublecheck delimiter and quoting chars; these are default from OpenOffice
spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
next(spamreader, None) # Skip the header row
for row in spamreader:
quest_start = date.fromisoformat(row[5]).strftime("%B %d, %Y")
quest_end = date.fromisoformat(row[6]).strftime("%B %d, %Y")
season = row[0].zfill(2)
episode = row[1].zfill(2)
with open("template.txt", "r", encoding="utf-8") as input_file:
text = input_file.read()
text = text.replace("{tkseason}", season)
text = text.replace("{tkepisode}", episode)
text = text.replace("{tktheme}", rot13(row[2]))
text = text.replace("{tknodetype}", row[3])
# text = text.replace("{tklength}", row[4]) # Reserved
text = text.replace("{tkstart}", quest_start)
text = text.replace("{tkend}", quest_end)
text = text.replace("{tknotes}", row[7])
#print(text)
html = markdown.markdown(text, extensions=['extra', 'smarty'])
with open("wordenchiladaS" + season + "E" + episode + ".html", "w",
encoding="utf-8", errors="xmlcharrefreplace") as output_file:
output_file.write(html)