diff --git a/README.md b/README.md index e906b8f..9ee6039 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # xdfcgi -A common gateway inferface (CGI) program written in C to display data related to Race CTS leaderboards of Xonotic servers. It may also serve as a static page generator. +A common gateway inferface (CGI) program written in C to display Race CTS leaderboards of Xonotic servers. It can also be a static page generator. ## Requirements sqlite-devel python3 python-sqlite @@ -28,17 +28,18 @@ The program queries the database `db/cts.db` (`./src/dbquery.c`, function `stati - Requests a player's ranks for all maps leaderboards s/he is present on. ## Usage: Static Page Generation -The CGI program is still invoked in static generation. The files `allmaps.py`, `output/leaderboard.css`, `template.html`, `template_map.html` help produce the output. + + python scripts/allmaps.py + +The CGI program is still invoked in static generation. The files `allmaps.py`, `output/leaderboard.css`, `overview.html`, `map.html` produce the output. Before executing `allmaps.py`, copy and modify the templates. - cp ./template-generic.html ./template.html - cp ./template_map-generic.html ./template_map.html + cp templates/overview.html . + cp templates/map.html . `allmaps.py` outputs an html file for all distinct maps in the database. The leaderboards for each map (equivalent to `?map=[map name]`) are in `output/maps/`. - python allmaps.py - ## Game Versions Used Under: * Xonotic 0.8.1 * Xonotic 0.8.2 @@ -46,6 +47,7 @@ Before executing `allmaps.py`, copy and modify the templates. ## Compilers * gcc (GCC) 10.2.1 * MinGW, GCC 4.7.1 + __________________ This program uses an sqlite3 database file created from `~/.xonotic/data/data/server.db`. diff --git a/output/leaderboard.css b/output/leaderboard.css index 2200d3d..030da72 100644 --- a/output/leaderboard.css +++ b/output/leaderboard.css @@ -1,5 +1,5 @@ -.footer { - margin:auto; +footer { + text-align:center; } table, th, td { border: 1px solid grey; diff --git a/scripts/allmaps.py b/scripts/allmaps.py index 025c5fb..b184cd1 100644 --- a/scripts/allmaps.py +++ b/scripts/allmaps.py @@ -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 diff --git a/template-generic.html b/template-generic.html deleted file mode 100644 index e2b7ba8..0000000 --- a/template-generic.html +++ /dev/null @@ -1,18 +0,0 @@ - - -
- - -