Tidy code

This commit is contained in:
Edward Betts 2023-09-08 19:03:51 +01:00
parent 5d257055a6
commit 3f573043a1

55
main.py
View file

@ -3,7 +3,6 @@
import collections
import json
import sys
import typing
from urllib.parse import unquote
@ -52,8 +51,7 @@ def start() -> str:
len(flickr_start) : flickr_url.find("/", len(flickr_start))
]
# nsid = flickr_usrename_to_nsid(flickr_username)
nsid = "disabled"
nsid = flickr_usrename_to_nsid(flickr_username)
assert nsid
print(nsid)
@ -95,56 +93,5 @@ def flickr_usrename_to_nsid(username: str) -> str:
return typing.cast(str, params["nsid"])
@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/")]
flickr_start = "https://flickr.com/photos/"
assert flickr_url.startswith(flickr_start)
flickr_username = flickr_url[
len(flickr_start) : flickr_url.find("/", len(flickr_start))
]
nsid = flickr_usrename_to_nsid(flickr_username)
assert nsid
print(nsid)
msg = flask.render_template(
"message.jinja",
flickr_url=flickr_url,
wikipedia_url=wikipedia_url,
name=name,
wiki_part1=wiki_part1,
wiki_part2=wiki_part2,
)
subject = f"Request to use your photo of {name} on Wikipedia"
lines = msg.split("\n\n")
return flask.render_template(
"show_message.html", subject=subject, lines=lines, nsid=nsid
)
if __name__ == "__main__":
app.run(host="0.0.0.0")