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.
This commit is contained in:
44
epilogue/redirector.py
Normal file
44
epilogue/redirector.py
Normal file
@@ -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/<path:path>')
|
||||||
|
def redirect_forums (path):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@app.route("/wiki/<path:path>")
|
||||||
|
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()
|
5
setup.py
5
setup.py
@@ -8,10 +8,11 @@ setup(
|
|||||||
description='Tools for exporting and creating archives of Glitch City Labs data',
|
description='Tools for exporting and creating archives of Glitch City Labs data',
|
||||||
author='Adrian Kuschelyagi Malacoda',
|
author='Adrian Kuschelyagi Malacoda',
|
||||||
packages=['epilogue'],
|
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={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'epilogue = epilogue:main'
|
'epilogue = epilogue:main',
|
||||||
|
'gclredirector = epilogue.redirector:main'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user