merged branch 'templates' (squash)

This commit is contained in:
2024-10-12 10:19:40 -07:00
parent 7bf2881145
commit c7753f4203
7 changed files with 70 additions and 54 deletions

View File

@@ -1,13 +1,13 @@
import sqlite3 as sql
import subprocess
import subprocess, traceback
# get all maps in database
def getmaps(database):
output = []
con = sql.connect(database)
with con:
cursor = con.cursor()
try:
# get all maps in database
cursor.execute("select distinct mapid from Cts_times;")
output = cursor.fetchall()
except sql.Error:
@@ -32,11 +32,11 @@ def renderindex(template):
def main():
template = ""
with open("template.html", 'r') as fin:
with open("overview.html", 'r') as fin:
template = fin.read()
renderindex(template)
maps = getmaps("db/cts.db")
with open("template_map.html", 'r') as fin:
with open("map.html", 'r') as fin:
template = fin.read()
# for each map generate an html file.
for game_map in maps:
@@ -47,10 +47,21 @@ def main():
filename = ("./output/maps/%s.html" % map_name)
with open(filename, 'w+') as fout:
title = map_name
fout.write(template % (title, map_name, table))
pass
fout.write(template.format(
title=title,
map_name=map_name,
table=table)
)
# fout.write(template % (title, map_name, table))
return True
if __name__ == "__main__":
print("allmaps.py - Generating .html files for all maps.")
main()
success = False
try:
success = main()
except FileNotFoundError:
traceback.print_exc()
print("\n\t The script probably didn't find the page templates needed to generate a page. You can copy minimal working examples from the repository at templates/.")
if success:
print("allmaps.py - Generated pages for all maps.")
pass