Combine into single page, add copy buttons.
This commit is contained in:
parent
0768cc101c
commit
5d257055a6
53
main.py
53
main.py
|
@ -22,11 +22,62 @@ def start() -> str:
|
|||
wikipedia_url = flask.request.args.get("wikipedia")
|
||||
if not wikipedia_url:
|
||||
return flask.render_template("combined.html")
|
||||
|
||||
start = wikipedia_url.find(enwiki) + len(enwiki)
|
||||
wiki_part2 = unquote(wikipedia_url[start:])
|
||||
|
||||
name = wiki_part2
|
||||
|
||||
if "_(" in name:
|
||||
name = name[: name.find("_(")]
|
||||
name = name.replace("_", " ")
|
||||
|
||||
flickr_url = flask.request.args.get("flickr")
|
||||
if not flickr_url:
|
||||
return flask.render_template(
|
||||
"combined.html",
|
||||
name=name,
|
||||
wikipedia_url=wikipedia_url,
|
||||
)
|
||||
|
||||
wiki_part1 = wikipedia_url[:start]
|
||||
|
||||
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)
|
||||
nsid = "disabled"
|
||||
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(
|
||||
"combined.html",
|
||||
name=unquote(wikipedia_url[start:]).replace("_", " "),
|
||||
name=name,
|
||||
wikipedia_url=wikipedia_url,
|
||||
flickr_url=flickr_url,
|
||||
subject=subject,
|
||||
lines=lines,
|
||||
nsid=nsid,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -20,11 +20,11 @@
|
|||
<p>Wikipedia article: {{ name }}</p>
|
||||
<p><a href="https://flickr.com/search/?view_all=1&safe_search=3&text={{ '"' + name + '"' | urlencode }}">Search flickr</a></p>
|
||||
|
||||
<form action="{{ url_for("show_message") }}">
|
||||
<form action="{{ url_for(request.endpoint) }}">
|
||||
<input type="hidden" name="wikipedia" value="{{ wikipedia_url }}"></input>
|
||||
<div class="mb-3">
|
||||
<label for="flickr" class="form-label">Flickr URL:</label>
|
||||
<input type="text" class="form-control" id="flickr" name="flickr" required>
|
||||
<input type="text" class="form-control" id="flickr" name="flickr" value="{{ flickr_url }}" required>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Submit">
|
||||
|
@ -32,6 +32,39 @@
|
|||
|
||||
{% endif %}
|
||||
|
||||
{% if flickr_url %}
|
||||
<p><a href="https://www.flickr.com/mail/write/?to={{nsid}}">send message</a>
|
||||
<div><strong>Subject:</strong> {{ subject }} <button class="btn btn-primary" id="copy-subject">copy</button>
|
||||
<div>
|
||||
<h3>message
|
||||
<button class="btn btn-primary" id="copy-message">copy</button>
|
||||
</h3>
|
||||
{% for p in lines %}
|
||||
<p>{{ p }}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
var copy_subject = document.getElementById("copy-subject");
|
||||
var copy_message = document.getElementById("copy-message");
|
||||
var subject = {{ subject | tojson }};
|
||||
var message = {{ "\n\n".join(lines) | tojson }};
|
||||
|
||||
copy_subject.addEventListener("click", function(e) {
|
||||
navigator.clipboard.writeText(subject);
|
||||
});
|
||||
|
||||
copy_message.addEventListener("click", function(e) {
|
||||
navigator.clipboard.writeText(message);
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue