From: Lanius Trolling Date: Sat, 27 Jan 2024 14:15:55 +0000 (-0500) Subject: Rename Python script X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=6f1d22b4a20a2412b153cc8845af778b8ac487b4;p=factbooks Rename Python script --- diff --git a/stuff/fix_quotes.py b/stuff/fix_quotes.py new file mode 100644 index 0000000..e4e379f --- /dev/null +++ b/stuff/fix_quotes.py @@ -0,0 +1,26 @@ +import json +import re + +quote_pattern = re.compile(r"^\"(.*)\" \- (.*?)\|(.*?)\@(.*?)$") + +quote_list = [] + +with open("../test/quotes.json", mode="r", encoding="utf-8") as quotes_json_file: + quote_list.extend(json.load(quotes_json_file)) + +with open("../test/quotes.txt", mode="r", encoding="utf-8") as quotes_file: + for quote in quotes_file: + quote = quote.rstrip() + match = quote_pattern.fullmatch(quote) + + text, author, portrait, link = match.groups() + quote_dict = { + "quote": text, + "author": author, + "portrait": "portrait-" + portrait.lower().replace(" ", "-").replace("'", ""), + "link": link.removeprefix("https://mechyrdia.info/lore/") + } + quote_list.append(quote_dict) + +with open("../test/quotes.json", mode="w", encoding="utf-8") as quotes_json_file: + json.dump(quote_list, quotes_json_file, indent="\t") diff --git a/stuff/fixquotes.py b/stuff/fixquotes.py deleted file mode 100644 index e4e379f..0000000 --- a/stuff/fixquotes.py +++ /dev/null @@ -1,26 +0,0 @@ -import json -import re - -quote_pattern = re.compile(r"^\"(.*)\" \- (.*?)\|(.*?)\@(.*?)$") - -quote_list = [] - -with open("../test/quotes.json", mode="r", encoding="utf-8") as quotes_json_file: - quote_list.extend(json.load(quotes_json_file)) - -with open("../test/quotes.txt", mode="r", encoding="utf-8") as quotes_file: - for quote in quotes_file: - quote = quote.rstrip() - match = quote_pattern.fullmatch(quote) - - text, author, portrait, link = match.groups() - quote_dict = { - "quote": text, - "author": author, - "portrait": "portrait-" + portrait.lower().replace(" ", "-").replace("'", ""), - "link": link.removeprefix("https://mechyrdia.info/lore/") - } - quote_list.append(quote_dict) - -with open("../test/quotes.json", mode="w", encoding="utf-8") as quotes_json_file: - json.dump(quote_list, quotes_json_file, indent="\t")