diff --git a/.gitignore b/.gitignore index fffc64d..bfed5fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ __pycache__ *.swp +venv +.vscode +.idea diff --git a/emojos.py b/emojos.py index 614eddb..dafc6da 100644 --- a/emojos.py +++ b/emojos.py @@ -25,13 +25,23 @@ app = Flask(__name__) @app.route('/') 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: - url = urllib.parse.urlunsplit( - ('https', domain, '/api/v1/custom_emojis', '', '')) - emojo = sorted(filter(lambda x: x.get('visible_in_picker', True), - requests.get(url).json()), - key=operator.itemgetter('shortcode')) - return render_template('emojo.html', domain=domain, emojo=emojo) + url = urllib.parse.urlunsplit(('https', domain, '/api/v1/custom_emojis', '', '')) + if show_all: + emojo = sorted(requests.get(url).json(), key=operator.itemgetter('shortcode')) + else: + emojo = sorted(filter(lambda x: x.get('visible_in_picker', True), requests.get(url).json()), + key=operator.itemgetter('shortcode')) + return render_template('emojo.html', domain=domain, emojo=emojo, show_animated=show_animated) except requests.exceptions.RequestException as e: return render_template('oh_no.html', domain=domain) @@ -48,8 +58,7 @@ def code(): session = botocore.session.get_session() # region name is detected from lambda environment client = session.create_client('lambda') - code = client.get_function(FunctionName=context.function_name, - Qualifier=context.function_version) + code = client.get_function(FunctionName=context.function_name, Qualifier=context.function_version) return redirect(code['Code']['Location'], code=303) @@ -57,7 +66,10 @@ def code(): def index(): if request.method == 'POST': 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: return redirect(url_for('index')) else: diff --git a/templates/emojo.html b/templates/emojo.html index 5535f08..7f67f51 100644 --- a/templates/emojo.html +++ b/templates/emojo.html @@ -6,12 +6,21 @@ click/touch to copy to clipboard

- {% for emoj in emojo %} -
-
:{{ emoj.shortcode }}:
-
:{{ emoj.shortcode }}:
-
- {% endfor %} + {% if show_animated %} + {% for emoj in emojo %} +
+
:{{ emoj.shortcode }}:
+
:{{ emoj.shortcode }}:
+
+ {% endfor %} + {% else %} + {% for emoj in emojo %} +
+
:{{ emoj.shortcode }}:
+
:{{ emoj.shortcode }}:
+
+ {% endfor %} + {% endif %}
{% endblock body %} {% block script %} diff --git a/templates/index.html b/templates/index.html index 8411328..93bbc56 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,7 +3,17 @@ {% block body %}

get the emojos for:

- +
+ +
+
+ + +
+
+ + +

(“emojo” is the semi-jokey term for custom emoji on Mastodon.)