Combine into single page, add copy buttons.

This commit is contained in:
Edward Betts 2023-09-08 19:03:07 +01:00
parent 0768cc101c
commit 5d257055a6
2 changed files with 87 additions and 3 deletions

53
main.py
View file

@ -22,13 +22,64 @@ def start() -> str:
wikipedia_url = flask.request.args.get("wikipedia") wikipedia_url = flask.request.args.get("wikipedia")
if not wikipedia_url: if not wikipedia_url:
return flask.render_template("combined.html") return flask.render_template("combined.html")
start = wikipedia_url.find(enwiki) + len(enwiki) 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( return flask.render_template(
"combined.html", "combined.html",
name=unquote(wikipedia_url[start:]).replace("_", " "), name=name,
wikipedia_url=wikipedia_url, 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=name,
wikipedia_url=wikipedia_url,
flickr_url=flickr_url,
subject=subject,
lines=lines,
nsid=nsid,
)
def get_params(line_iter: collections.abc.Iterable[str]) -> str: def get_params(line_iter: collections.abc.Iterable[str]) -> str:
"""Find and return params from flickr profile page.""" """Find and return params from flickr profile page."""

View file

@ -20,11 +20,11 @@
<p>Wikipedia article: {{ name }}</p> <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> <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> <input type="hidden" name="wikipedia" value="{{ wikipedia_url }}"></input>
<div class="mb-3"> <div class="mb-3">
<label for="flickr" class="form-label">Flickr URL:</label> <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> </div>
<input type="submit" value="Submit"> <input type="submit" value="Submit">
@ -32,6 +32,39 @@
{% endif %} {% 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>
</div> </div>
{% endblock %} {% 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 %}