diff --git a/puppet_links_sheet/config.txt b/puppet_links_sheet/config.txt index 59f09b1..b7294bb 100644 --- a/puppet_links_sheet/config.txt +++ b/puppet_links_sheet/config.txt @@ -8,7 +8,12 @@ # In both cases, {} will be replaced with the name of the puppet Number rows: yes +# Your nation name, for the script-generated links to identify themselves. +# Define it like in the following example: +# User nation: INSERT_YOUR_NATION_NAME_HERE +User nation: +# baseURL: https://www.nationstates.net [links] # Links are relative to the NS site. @@ -23,104 +28,3 @@ Value Deck (No CSS): page=deck/value_deck=1/template-overall=none Telegrams: page=telegrams Settings: page=settings TG Settings: page=tgsettings - -[html_template] -# text and background color. Switched around in dark mode -dark_color = #111 -light_color = #FFF - -border_color = darkorange - -hover_light_color = #DDD -hover_dark_color = #444 - -# -# Edit the following at your own risk -# -html_start = - - - - - - - -html_end = -
- - - diff --git a/puppet_links_sheet/generatehtml.py b/puppet_links_sheet/generatehtml.py index 4dc00f1..bcc33ba 100755 --- a/puppet_links_sheet/generatehtml.py +++ b/puppet_links_sheet/generatehtml.py @@ -96,6 +96,116 @@ def create_output_files(*params): return None +def cleanup(str): + return re.sub(invalid_nation_chars, "", str) + + +def mk_generated_by(user): + if not hasattr(mk_generated_by, "fmt"): + mk_generated_by.fmt = "github_dithpri_RCES_generatehtml.py_0.2__usedBy_{}" + user = cleanup(user) + return mk_generated_by.fmt.format(user) + + +html_start = """ + + + + + + + +""" +html_end = """ +
+ + + +""" + + def main(): config_files = get_config_files("config.txt", "puppets_list.txt") outputs = create_output_files( @@ -116,8 +226,17 @@ def main(): except KeyError: container_prefix = "container={}/nation={}" - html_start = config["html_template"]["html_start"] - html_end = config["html_template"]["html_end"] + try: + baseURL = config["config"]["baseURL"] + except KeyError: + baseURL = "https://www.nationstates.net" + + try: + user_nation = cleanup(canonicalize(config["config"]["user nation"])) + if user_nation == "" or user_nation is None: + raise Exception("User nation is invalid or not defined") + except KeyError: + raise Exception("User nation not found in config file") links.write(html_start) @@ -149,15 +268,23 @@ def main(): if config["config"]["number rows"] in ["yes", "true", "1"]: links.write("\t{}".format(puppet_number)) links.write( - '\t

{}

\n'.format( - container_protolink, canonical, nation + '\t

{}

\n'.format( + baseURL, + container_protolink, + canonical, + mk_generated_by(user_nation), + nation, ) ) try: for key, value in config["links"].items(): links.write( - '\t

{}

\n'.format( - container_protolink, value, key + '\t

{}

\n'.format( + baseURL, + container_protolink, + value, + mk_generated_by(user_nation), + key, ) ) except KeyError: