commit 084c886933adc4929d42efee6e868c6cae8c5207 Author: Edward Betts Date: Fri Sep 8 01:10:09 2023 +0100 Initial commit diff --git a/main.py b/main.py new file mode 100755 index 0000000..e10ede5 --- /dev/null +++ b/main.py @@ -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") diff --git a/templates/message.jinja b/templates/message.jinja new file mode 100644 index 0000000..a60e2e5 --- /dev/null +++ b/templates/message.jinja @@ -0,0 +1,25 @@ +{# vim:ft=jinja +#} +Request to use your photo of {{ name }} on Wikipedia + +Hi, + +I wanted to get in touch regarding your photo of {{ name }}, which I came across on Flickr: + +{{ flickr_url }} + +I am currently working on enhancing the Wikipedia article about {{ name }}, and I believe your image would be a valuable addition to the article. However, to use it on Wikipedia, we need to ensure that it's available under the Creative Commons Attribution (CC BY) license or the Attribution-ShareAlike (CC BY-SA) license. These licenses allow us to use the image with proper attribution. + +{{ wiki_part1 }}{{ wiki_part2 | urlencode }} + +If you're open to it, could you please consider changing the license of this photo to either CC BY or CC BY-SA? We would, of course, provide full credit on the image page, acknowledging your contribution. + +To adjust the license settings, you can click on 'All rights reserved' on the right-hand side of the photo's page, just underneath the date. + +Your generosity in allowing us to use this image would greatly enhance the quality of the Wikipedia article and contribute to the dissemination of knowledge about {{ name }}. + +Thank you for your consideration, and if you have any questions or require further information, please don't hesitate to contact me. + +Warm regards, + +Edward diff --git a/templates/show_message.html b/templates/show_message.html new file mode 100644 index 0000000..a6e49d1 --- /dev/null +++ b/templates/show_message.html @@ -0,0 +1,11 @@ + + + + + + + + +
{{ msg }}
+ + diff --git a/templates/start_form.html b/templates/start_form.html new file mode 100644 index 0000000..a4ac8d4 --- /dev/null +++ b/templates/start_form.html @@ -0,0 +1,19 @@ + + + + URL Input Form + + +

Enter URLs

+
+ +

+ + +

+ + +
+ + +