Merge pull request #12 from yingziwu/mistress

Add options
This commit is contained in:
iliana destroyer of worlds 2019-08-28 16:32:10 -07:00 committed by GitHub
commit cbb3e6ea41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 16 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
__pycache__ __pycache__
*.swp *.swp
venv
.vscode
.idea

View File

@ -25,13 +25,23 @@ app = Flask(__name__)
@app.route('/<domain>') @app.route('/<domain>')
def emojo(domain): def emojo(domain):
if request.args.get('show_all', '') == 'on':
show_all = True
else:
show_all = False
if request.args.get('show_animated', '') == 'on':
show_animated = True
else:
show_animated = False
try: try:
url = urllib.parse.urlunsplit( url = urllib.parse.urlunsplit(('https', domain, '/api/v1/custom_emojis', '', ''))
('https', domain, '/api/v1/custom_emojis', '', '')) if show_all:
emojo = sorted(filter(lambda x: x.get('visible_in_picker', True), emojo = sorted(requests.get(url).json(), key=operator.itemgetter('shortcode'))
requests.get(url).json()), else:
emojo = sorted(filter(lambda x: x.get('visible_in_picker', True), requests.get(url).json()),
key=operator.itemgetter('shortcode')) key=operator.itemgetter('shortcode'))
return render_template('emojo.html', domain=domain, emojo=emojo) return render_template('emojo.html', domain=domain, emojo=emojo, show_animated=show_animated)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
return render_template('oh_no.html', domain=domain) return render_template('oh_no.html', domain=domain)
@ -48,8 +58,7 @@ def code():
session = botocore.session.get_session() session = botocore.session.get_session()
# region name is detected from lambda environment # region name is detected from lambda environment
client = session.create_client('lambda') client = session.create_client('lambda')
code = client.get_function(FunctionName=context.function_name, code = client.get_function(FunctionName=context.function_name, Qualifier=context.function_version)
Qualifier=context.function_version)
return redirect(code['Code']['Location'], code=303) return redirect(code['Code']['Location'], code=303)
@ -57,7 +66,10 @@ def code():
def index(): def index():
if request.method == 'POST': if request.method == 'POST':
if 'instance' in request.form: if 'instance' in request.form:
return redirect(url_for('emojo', domain=request.form['instance'])) show_all = request.form.get('show_all')
show_animated = request.form.get('show_animated')
return redirect(
url_for('emojo', domain=request.form['instance'], show_all=show_all, show_animated=show_animated))
else: else:
return redirect(url_for('index')) return redirect(url_for('index'))
else: else:

View File

@ -6,12 +6,21 @@
click/touch to copy to clipboard click/touch to copy to clipboard
</p> </p>
<dl class="emojo"> <dl class="emojo">
{% if show_animated %}
{% for emoj in emojo %}
<div>
<dt><img src="{{ emoj.url }}" alt=":{{ emoj.shortcode }}:"></dt>
<dd>:{{ emoj.shortcode }}:</dd>
</div>
{% endfor %}
{% else %}
{% for emoj in emojo %} {% for emoj in emojo %}
<div> <div>
<dt><img src="{{ emoj.static_url }}" alt=":{{ emoj.shortcode }}:"></dt> <dt><img src="{{ emoj.static_url }}" alt=":{{ emoj.shortcode }}:"></dt>
<dd>:{{ emoj.shortcode }}:</dd> <dd>:{{ emoj.shortcode }}:</dd>
</div> </div>
{% endfor %} {% endfor %}
{% endif %}
</dl> </dl>
{% endblock body %} {% endblock body %}
{% block script %} {% block script %}

View File

@ -3,7 +3,17 @@
{% block body %} {% block body %}
<p>get the emojos for:</p> <p>get the emojos for:</p>
<form method="POST" action=""> <form method="POST" action="">
<div>
<input type="text" name="instance" placeholder="instance.domain"> <input type="text" name="instance" placeholder="instance.domain">
</div>
<div>
<input type="checkbox" name="show_all">
<label for="show_all">See unlisted emojos</label>
</div>
<div>
<input type="checkbox" name="show_animated">
<label for="show_animated">See animated emojos</label>
</div>
<input type="submit" value="go"> <input type="submit" value="go">
</form> </form>
<p>(&ldquo;emojo&rdquo; is the semi-jokey term for custom emoji on <a href="https://joinmastodon.org">Mastodon</a>.)</p> <p>(&ldquo;emojo&rdquo; is the semi-jokey term for custom emoji on <a href="https://joinmastodon.org">Mastodon</a>.)</p>