Implement run.py
This commit is contained in:
parent
15e8e60f3a
commit
f3c0921728
8 changed files with 88 additions and 27 deletions
|
@ -11,7 +11,7 @@ gen_index.generate("../templates", "..", "index.html")
|
|||
print("Generating leaderboard pages for each category...")
|
||||
gen_categories.generate("../templates", "../categories", "category.html")
|
||||
|
||||
# print("Generating details pages for each run...")
|
||||
# gen_runs.generate("../templates", "runs", "runs.html")
|
||||
print("Generating details pages for each run...")
|
||||
gen_runs.generate("../templates", "../runs", "run.html")
|
||||
|
||||
print("Done generating site!")
|
||||
|
|
|
@ -42,7 +42,7 @@ def dictWriter(filepath, dict, flag="w"):
|
|||
def dictReaderFirstRow(filepath):
|
||||
"""Get a dictionary of the first (non-header) row of values in a csv
|
||||
|
||||
filepath -- the path of the csv, whether or not it exists\n
|
||||
filepath -- the path of the csv\n
|
||||
"""
|
||||
with open(filepath, newline="") as file:
|
||||
dict = {}
|
||||
|
@ -59,7 +59,7 @@ def dictReaderFirstRow(filepath):
|
|||
def dictReaderMultiRow(filepath, idName):
|
||||
"""Get a dictionary of dictionaries of the (non-header) row of values in a csv
|
||||
|
||||
filepath -- the path of the csv, whether or not it exists\n
|
||||
filepath -- the path of the csv\n
|
||||
idName -- the property in the header of the csv to use as each key of the resulting dictionary\n
|
||||
"""
|
||||
with open(filepath, newline="") as file:
|
||||
|
|
|
@ -2,6 +2,12 @@
|
|||
|
||||
|
||||
def replaceTextInFile(filepath, oldText, newText):
|
||||
"""Replace all occurrences of some text in plaintext file with some other text.
|
||||
|
||||
filepath -- the path of the plaintext file\n
|
||||
oldText -- the text to replace\n
|
||||
newText -- the text to implement\n
|
||||
"""
|
||||
file = open(filepath, "rt")
|
||||
newFile = file.read().replace(oldText, newText)
|
||||
file.close()
|
||||
|
|
|
@ -9,18 +9,18 @@ import os
|
|||
def generate(templatedir, destinationdir, templateFilename):
|
||||
"""Main generation function for category page generation helper.
|
||||
|
||||
templatedir -- the relative path of the template html file's directory
|
||||
destinationpath -- the directory where category paths should be generated
|
||||
filename -- the filename of the category template (always category.html)
|
||||
templatedir -- the relative path of the template html file's directory\n
|
||||
destinationpath -- the directory where category paths should be generated\n
|
||||
templateFilename -- the filename of the category template (always category.html)\n
|
||||
"""
|
||||
|
||||
idName = "tk_category_dashname"
|
||||
categories = util_csv.dictReaderMultiRow("../csv/categories.csv", idName)
|
||||
categoryIdName = "tk_category_dashname"
|
||||
categories = util_csv.dictReaderMultiRow("../csv/categories.csv", categoryIdName)
|
||||
config = util_csv.dictReaderFirstRow("../csv/config.csv")
|
||||
|
||||
for category in categories:
|
||||
|
||||
path = f"{destinationdir}/{categories[category][idName]}"
|
||||
path = f"{destinationdir}/{categories[category][categoryIdName]}"
|
||||
currentDir = os.getcwd()
|
||||
|
||||
os.makedirs(path, exist_ok=True)
|
||||
|
|
|
@ -8,9 +8,9 @@ import shutil
|
|||
def generate(templatedir, destinationdir, templateFilename):
|
||||
"""Main generation function for index.html generation helper.
|
||||
|
||||
templatedir -- the relative path of the template html file's directory
|
||||
destinationpath -- the directory where index.html should be generated
|
||||
filename -- the filename of the index template (always index.html)
|
||||
templatedir -- the relative path of the template html file's directory\n
|
||||
destinationpath -- the directory where index.html should be generated\n
|
||||
templateFilename -- the filename of the index template (always index.html)\n
|
||||
"""
|
||||
|
||||
shutil.copy(f"{templatedir}/{templateFilename}", destinationdir)
|
||||
|
@ -24,6 +24,8 @@ def generate(templatedir, destinationdir, templateFilename):
|
|||
|
||||
tk_category_dashname = "tk_category_dashname"
|
||||
tk_category_name = "tk_category_name"
|
||||
|
||||
# lk_categories handler
|
||||
for category in categories:
|
||||
|
||||
util_file.replaceTextInFile(
|
||||
|
|
|
@ -7,22 +7,22 @@ import os
|
|||
|
||||
|
||||
def generate(templatedir, destinationdir, templateFilename):
|
||||
"""Main generation function for category page generation helper.
|
||||
"""Main generation function for run page generation helper.
|
||||
|
||||
templatedir -- the relative path of the template html file's directory
|
||||
destinationpath -- the directory where run paths should be generated
|
||||
filename -- the filename of the run template (always run.html)
|
||||
templatedir -- the relative path of the template html file's directory\n
|
||||
destinationpath -- the directory where run paths should be generated\n
|
||||
templateFilename -- the filename of the run template (always run.html)\n
|
||||
"""
|
||||
|
||||
# TODO fix everything
|
||||
|
||||
idName = "tk_category_dashname"
|
||||
categories = util_csv.dictReaderMultiRow("../csv/categories.csv", idName)
|
||||
runIdName = "tk_run_id"
|
||||
categoryIdName = "tk_category_dashname"
|
||||
runs = util_csv.dictReaderMultiRow("../csv/runs.csv", runIdName)
|
||||
categories = util_csv.dictReaderMultiRow("../csv/categories.csv", categoryIdName)
|
||||
config = util_csv.dictReaderFirstRow("../csv/config.csv")
|
||||
|
||||
for category in categories:
|
||||
for run in runs:
|
||||
|
||||
path = f"{destinationdir}/{categories[category][idName]}"
|
||||
path = f"{destinationdir}/{runs[run][runIdName]}"
|
||||
currentDir = os.getcwd()
|
||||
|
||||
os.makedirs(path, exist_ok=True)
|
||||
|
@ -32,10 +32,30 @@ def generate(templatedir, destinationdir, templateFilename):
|
|||
f"{currentDir}/{path}/index.html",
|
||||
)
|
||||
|
||||
for key in categories[category]:
|
||||
tk_run_link = ""
|
||||
for key in runs[run]:
|
||||
util_file.replaceTextInFile(f"{path}/index.html", key, runs[run][key])
|
||||
if key == "tk_run_link":
|
||||
tk_run_link = runs[run][key]
|
||||
|
||||
for key in categories[runs[run]["tk_run_category_dashname"]]:
|
||||
util_file.replaceTextInFile(
|
||||
f"{path}/index.html", key, categories[category][key]
|
||||
f"{path}/index.html",
|
||||
key,
|
||||
categories[runs[run]["tk_run_category_dashname"]][key],
|
||||
)
|
||||
|
||||
for key in config.keys():
|
||||
util_file.replaceTextInFile(f"{path}/index.html", key, config[key])
|
||||
|
||||
# lk_run_link handler
|
||||
if tk_run_link == "":
|
||||
util_file.replaceTextInFile(
|
||||
f"{path}/index.html", "lk_run_link", "No recording available"
|
||||
)
|
||||
else:
|
||||
util_file.replaceTextInFile(
|
||||
f"{path}/index.html",
|
||||
"lk_run_link",
|
||||
f'<a class="runLink" href="{tk_run_link}">Run recording</a>',
|
||||
)
|
||||
|
|
|
@ -22,11 +22,11 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
<h1>tk_game_name - tk_category_name</h1>
|
||||
<h1><a href="../../">tk_game_name</a> - tk_category_name</h1>
|
||||
<p>tk_category_description</p>
|
||||
|
||||
<h2>Leaderboard</h2>
|
||||
<!-- lk_leaderboard -->
|
||||
lk_leaderboard
|
||||
</body>
|
||||
|
||||
</html>
|
33
templates/run.html
Normal file
33
templates/run.html
Normal file
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>tk_game_name - tk_run_runner's run</title>
|
||||
|
||||
<link rel="stylesheet" href="../../css/style.css">
|
||||
<link rel="icon" href="../../assets/img/logo.png">
|
||||
|
||||
<meta property="og:title" content="tk_game_name - tk_run_runner's run" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:description" content="tk_run_description" />
|
||||
<meta property="og:url" content="tk_url/tk_run_id/index.html" />
|
||||
<meta property="og:image:secure_url" content="https://tk_url/assets/img/logo.png" />
|
||||
<meta property="og:image:alt" content="tk_logo_alt" />
|
||||
|
||||
<!-- Placeholder og:locale, replace content with your own if desired. -->
|
||||
<meta property="og:locale" content="en_US" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1><a href="../../">tk_game_name</a> - tk_run_runner's run</h1>
|
||||
<h2><a href="../../categories/tk_category_dashname">tk_category_name<a></h2>
|
||||
<p>Verified by <strong>tk_run_verifier</strong></p>
|
||||
<p>Took place on <strong>tk_run_date</strong></p>
|
||||
lk_run_link
|
||||
<p class="runDescription"><em>tk_run_description</em></p>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in a new issue