2022-02-09 09:02:02 +05:30
import sqlite3 as sql
2024-10-12 22:49:40 +05:30
import subprocess , traceback
2022-02-09 09:02:02 +05:30
2024-10-12 22:49:40 +05:30
# get all maps in database
2022-02-09 09:02:02 +05:30
def getmaps ( database ) :
output = [ ]
con = sql . connect ( database )
with con :
cursor = con . cursor ( )
try :
cursor . execute ( " select distinct mapid from Cts_times; " )
output = cursor . fetchall ( )
except sql . Error :
print ( " Shit is fucked. " )
return output
# if there is no query then it outputs the index file.
def getcontent ( query = None ) :
cmd = [ ( " ./cts " ) ]
proc = subprocess . Popen ( cmd , env = query , stdout = subprocess . PIPE , shell = True )
# communicate returns 'bytes' class with function 'decode'
return proc . communicate ( ) [ 0 ] . decode ( ' utf-8 ' )
def renderindex ( template ) :
# no env variable
table = getcontent ( )
filename = " ./output/index.html "
with open ( filename , ' w+ ' ) as fout :
2022-02-17 07:11:34 +05:30
fout . write ( template % ( table ) )
2022-02-09 09:02:02 +05:30
fout . close
pass
def main ( ) :
template = " "
2024-10-12 22:49:40 +05:30
with open ( " overview.html " , ' r ' ) as fin :
2022-02-09 09:02:02 +05:30
template = fin . read ( )
renderindex ( template )
maps = getmaps ( " db/cts.db " )
2024-10-12 22:49:40 +05:30
with open ( " map.html " , ' r ' ) as fin :
2022-02-17 07:11:34 +05:30
template = fin . read ( )
2022-02-20 20:30:01 +05:30
# for each map generate an html file.
2022-02-09 09:02:02 +05:30
for game_map in maps :
# game_map is a tuple obj.
map_name = game_map [ 0 ]
query = { " QUERY_STRING " : ( " map= %s " % map_name ) }
table = getcontent ( query )
2022-02-17 07:11:34 +05:30
filename = ( " ./output/maps/ %s .html " % map_name )
2022-02-09 09:02:02 +05:30
with open ( filename , ' w+ ' ) as fout :
2022-02-17 07:11:34 +05:30
title = map_name
2024-10-12 22:49:40 +05:30
fout . write ( template . format (
title = title ,
map_name = map_name ,
table = table )
)
# fout.write(template % (title, map_name, table))
return True
2022-02-09 09:02:02 +05:30
if __name__ == " __main__ " :
2024-10-12 22:49:40 +05:30
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. " )
2022-02-09 09:02:02 +05:30
pass