Working index gen (minus categories)

This commit is contained in:
Zachary Talis 2021-06-23 19:38:47 -04:00
parent eeb582169a
commit 1460d137b3
5 changed files with 52 additions and 10 deletions

View file

@ -4,7 +4,7 @@ from utils.gen import index as gen_index
from utils.gen import categories as gen_categories from utils.gen import categories as gen_categories
from utils.gen import runs as gen_runs from utils.gen import runs as gen_runs
gen_index.generate() gen_index.generate("../templates", "..", "index.html")
gen_categories.generate() gen_categories.generate()
gen_runs.generate() gen_runs.generate()

View file

@ -8,20 +8,20 @@ print(
f"\nWelcome to paceboard! Let's set up your leaderboard site :)\nWe'll save this info in csv/config.csv\n\n{divider}\n" f"\nWelcome to paceboard! Let's set up your leaderboard site :)\nWe'll save this info in csv/config.csv\n\n{divider}\n"
) )
tk_game = input("Your game's name: ") tk_game_name = input("Your game's name: ")
tk_description = input("Description for your game: ") tk_game_description = input("Description for your game: ")
tk_url = input("URL of your site (format example - foobar.com): ") tk_url = input("URL of your site (format example - foobar.com): ")
tk_logo_alt = input("Description of your game's logo (this is used for alt-text): ") tk_logo_alt = input("Description of your game's logo (this is used for alt-text): ")
print(
f"\n{divider}\n\nPerfect! You can always overwrite the info above by running this script again.\nHere's an overview of how to use paceboard:\n\n- Add a category using scripts/add-category.py\n- Add a run using scripts/add-run.py\n- Use scripts/generate.py to update the site with the info you've added.\n- All categories, runs, and configuration details are stored in csv/\n- Replace the logo saved as assets/img/logo.png\n- For the adventurous, you can restyle your site's pages by editing files within templates/ and css/\n\nRemember to run scripts/generate.py to initialize your site.\nThat's all for now! <3\n"
)
configDict = { configDict = {
"tk_game": tk_game, "tk_game_name": tk_game_name,
"tk_description": tk_description, "tk_game_description": tk_game_description,
"tk_url": tk_url, "tk_url": tk_url,
"tk_logo_alt": tk_logo_alt, "tk_logo_alt": tk_logo_alt,
} }
util_csv.dictWriterSingleDict("../csv/config.csv", configDict) util_csv.dictWriterSingleDict("../csv/config.csv", configDict)
print(
f"\n{divider}\n\nPerfect! You can always overwrite the info above by running this script again.\nHere's an overview of how to use paceboard:\n\n- Add a category using scripts/add-category.py\n- Add a run using scripts/add-run.py\n- Use scripts/generate.py to update the site with the info you've added.\n- All categories, runs, and configuration details are stored in csv/\n- Replace the logo saved as assets/img/logo.png\n- For the adventurous, you can restyle your site's pages by editing files within templates/ and css/\n\nRemember to run scripts/generate.py to initialize your site.\nThat's all for now! <3\n"
)

View file

@ -1,6 +1,7 @@
### Util library for interacting with csv files ### Util library for interacting with csv files
import csv import csv
import os
def readerWithFunction(filepath, function, arg=None): def readerWithFunction(filepath, function, arg=None):
@ -35,6 +36,20 @@ def dictWriterSingleDict(filepath, dict):
file.close() file.close()
def dictReaderFirstRow(filepath):
with open(filepath, newline="") as file:
print(os.path.abspath(filepath))
dict = {}
dictReader = csv.DictReader(file)
for row in dictReader:
firstRow = True
if firstRow:
dict = row
firstRow = False
file.close()
return dict
def getIndexOfField(filepath, field): def getIndexOfField(filepath, field):
"""Get the index (column number) of a field in a csv. """Get the index (column number) of a field in a csv.

10
scripts/utils/file.py Normal file
View file

@ -0,0 +1,10 @@
### Util library for general file handling
def replaceTextInFile(filepath, oldText, newText):
file = open(filepath, "rt")
newFile = file.read().replace(oldText, newText)
file.close()
file = open(filepath, "wt")
file.write(newFile)
file.close

View file

@ -1,5 +1,22 @@
### Generation helper for index.html ### Generation helper for index.html
from .. import file as util_file
from .. import csv as util_csv
import shutil
def generate():
def generate(templatedir, destinationdir, filename):
"""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 page (always index.html)
"""
print("- index.py -") print("- index.py -")
shutil.copy(f"{templatedir}/{filename}", destinationdir)
config = util_csv.dictReaderFirstRow("../csv/config.csv")
for key in config.keys():
util_file.replaceTextInFile(f"{destinationdir}/{filename}", key, config[key])