From 2e73ecd59ffe848f1ef334862d774462e2f1f991 Mon Sep 17 00:00:00 2001 From: Adrian Malacoda Date: Mon, 24 Aug 2020 00:24:45 -0500 Subject: [PATCH] Begin work on redirector webapp. The logic for redirecting wiki pages -seems- consistent with how the archives are generated but... nginx is normalizing the %2Fs into slashes and therefore not able to access any files with that escape sequence (e.g. Gold%2FSilver). Might need to find another character to escape / with. + might work, it's semantically acceptable (e.g. "Gold+Silver" in place of "Gold/Silver") although this character is sometimes interpreted equivalently to a space. Regardless, nginx seems to be happy with it so might go with it. May also need to test on a web host e.g. my old tripod account to see if assumptions hold up there too. --- epilogue/redirector.py | 44 ++++++++++++++++++++++++++++++++++++++++++ setup.py | 5 +++-- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 epilogue/redirector.py diff --git a/epilogue/redirector.py b/epilogue/redirector.py new file mode 100644 index 0000000..cb18ee4 --- /dev/null +++ b/epilogue/redirector.py @@ -0,0 +1,44 @@ +import argparse + +from flask import Flask, redirect +app = Flask(__name__) + +def is_wiki_directory_name (name): + return "Dex" in name + +def escape_wiki_page_name (page_name): + page_name = page_name[0].upper() + page_name[1:].replace(" ", "_") + + if page_name.endswith("/"): + page_name = page_name[:-1] + + if "/" in page_name: + (prefix, suffix) = page_name.split("/", 1) + suffix = suffix.replace("/", "%2F") + page_name = prefix + ("/" if is_wiki_directory_name(prefix) else "%2F") + suffix + + return page_name + +def make_wiki_url (path): + url = app.args.wiki_archive + + if not url.endswith("/"): + url = url + "/" + + return url + escape_wiki_page_name(path) + ".html" + +@app.route('/forums/') +def redirect_forums (path): + pass + +@app.route("/wiki/") +def redirect_wiki (path): + return redirect(make_wiki_url(path)) + +def main (): + parser = argparse.ArgumentParser() + parser.add_argument("--wiki-archive", help="URL to wiki archive") + parser.add_argument("--forums-archive", help="URL to forums archive") + + app.args = parser.parse_args() + app.run() \ No newline at end of file diff --git a/setup.py b/setup.py index 2da093b..98c14b6 100644 --- a/setup.py +++ b/setup.py @@ -8,10 +8,11 @@ setup( description='Tools for exporting and creating archives of Glitch City Labs data', author='Adrian Kuschelyagi Malacoda', packages=['epilogue'], - install_requires=['pysqlite3 >= 0.4.3', 'chevron >= 0.13.1', 'bbcode >= 1.1.0', 'mwparserfromhell >= 0.5.4'], + install_requires=['pysqlite3 >= 0.4.3', 'chevron >= 0.13.1', 'bbcode >= 1.1.0', 'mwparserfromhell >= 0.5.4', 'flask >= 1.1.2'], entry_points={ 'console_scripts': [ - 'epilogue = epilogue:main' + 'epilogue = epilogue:main', + 'gclredirector = epilogue.redirector:main' ] } )