merged branch 'templates' (squash)
This commit is contained in:
parent
7bf2881145
commit
c7753f4203
14
README.md
14
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`.
|
||||
|
@ -1,5 +1,5 @@
|
||||
.footer {
|
||||
margin:auto;
|
||||
footer {
|
||||
text-align:center;
|
||||
}
|
||||
table, th, td {
|
||||
border: 1px solid grey;
|
||||
|
@ -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
|
||||
|
@ -1,18 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>CTS Leaderboards - Add your title here</title>
|
||||
<link href="./leaderboard.css" rel="stylesheet" type="text/css" media="all">
|
||||
</head>
|
||||
|
||||
<div class = "content">
|
||||
%s
|
||||
|
||||
<div class = "footer">
|
||||
<center><p> Page generated using <a href="https://git.teknik.io/scuti/xdfcgi">xdfcgi</a> by scuti.</p></center>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</html>
|
@ -1,20 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>%s - CTS Leaderboards - Add your title here</title>
|
||||
<link href="../leaderboard.css" rel="stylesheet" type="text/css" media="all">
|
||||
</head>
|
||||
|
||||
<div class = "content">
|
||||
<h3>%s</h3>
|
||||
|
||||
%s
|
||||
|
||||
<div class = "footer">
|
||||
<center><p> Page generated using <a href="https://git.teknik.io/scuti/xdfcgi">xdfcgi</a> by scuti.</p></center>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</html>
|
22
templates/map.html
Normal file
22
templates/map.html
Normal file
@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{title} - Leaderboards - Minimal Working Example</title>
|
||||
<link href="/style.css" rel="stylesheet" type="text/css" media="all">
|
||||
<link href="../leaderboard.css" rel="stylesheet" type="text/css" media="all">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- map name -->
|
||||
<h1>{map_name}</h1>
|
||||
|
||||
<!-- code generated table goes here -->
|
||||
{table}
|
||||
|
||||
<footer>
|
||||
<p>Page generated using <a href="https://notabug.org/scuti/xdfcgi">xdfcgi</a> by <a href="https://scuti.neocities.org/">scuti</a></p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
19
templates/overview.html
Normal file
19
templates/overview.html
Normal file
@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>CTS Leaderboards - Minimal Working Example</title>
|
||||
<link href="/style.css" rel="stylesheet" type="text/css" media="all">
|
||||
<link href="./leaderboard.css" rel="stylesheet" type="text/css" media="all">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- code generated table goes here -->
|
||||
%s
|
||||
|
||||
<footer>
|
||||
<p>Page generated using <a href="https://notabug.org/scuti/xdfcgi">xdfcgi</a> by <a href="https://scuti.neocities.org/">scuti</a></p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user