Initial commit
This commit is contained in:
commit
084c886933
4 changed files with 110 additions and 0 deletions
55
main.py
Executable file
55
main.py
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
from urllib.parse import unquote
|
||||
|
||||
import flask
|
||||
|
||||
app = flask.Flask(__name__)
|
||||
app.debug = True
|
||||
|
||||
enwiki = "en.wikipedia.org/wiki/"
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def start_form() -> str:
|
||||
"""Start form."""
|
||||
return flask.render_template("start_form.html")
|
||||
|
||||
|
||||
@app.route("/message")
|
||||
def show_message() -> str:
|
||||
"""Show message."""
|
||||
flickr_url = flask.request.args["flickr"]
|
||||
wikipedia_url = flask.request.args["wikipedia"]
|
||||
|
||||
start = wikipedia_url.find(enwiki) + len(enwiki)
|
||||
wiki_part1 = wikipedia_url[:start]
|
||||
|
||||
if len(sys.argv) > 4:
|
||||
name = sys.argv[4]
|
||||
else:
|
||||
wiki_part2 = unquote(wikipedia_url[start:])
|
||||
name = wiki_part2
|
||||
|
||||
if "_(" in name:
|
||||
name = name[: name.find("_(")]
|
||||
name = name.replace("_", " ")
|
||||
|
||||
if "/in/" in flickr_url:
|
||||
flickr_url = flickr_url[: flickr_url.find("/in/")]
|
||||
|
||||
msg = flask.render_template(
|
||||
"message.jinja",
|
||||
flickr_url=flickr_url,
|
||||
wikipedia_url=wikipedia_url,
|
||||
name=name,
|
||||
wiki_part1=wiki_part1,
|
||||
wiki_part2=wiki_part2,
|
||||
)
|
||||
|
||||
return flask.render_template("show_message.html", msg=msg)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0")
|
||||
Loading…
Add table
Add a link
Reference in a new issue