lint massacre
This commit is contained in:
parent
f4809d9d71
commit
a713371a24
17
app.py
17
app.py
|
@ -13,7 +13,6 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import operator
|
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
import botocore.session
|
import botocore.session
|
||||||
|
@ -25,17 +24,21 @@ from flask import Flask, redirect, render_template, request, url_for
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
def slug_filter(s):
|
def slug_filter(s):
|
||||||
return s.lower().replace(" ", "-")
|
return s.lower().replace(" ", "-")
|
||||||
|
|
||||||
|
|
||||||
app.jinja_env.filters["slug"] = slug_filter
|
app.jinja_env.filters["slug"] = slug_filter
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Emoj:
|
class Emoj:
|
||||||
__slots__ = frozenset({"shortcode", "url"})
|
__slots__ = frozenset({"shortcode", "url"})
|
||||||
shortcode: str
|
shortcode: str
|
||||||
url: str
|
url: str
|
||||||
|
|
||||||
|
|
||||||
@app.route("/<domain>")
|
@app.route("/<domain>")
|
||||||
def emojo(domain):
|
def emojo(domain):
|
||||||
if request.args.get("show_all", "") == "on":
|
if request.args.get("show_all", "") == "on":
|
||||||
|
@ -47,9 +50,7 @@ def emojo(domain):
|
||||||
else:
|
else:
|
||||||
show_animated = False
|
show_animated = False
|
||||||
|
|
||||||
url = urllib.parse.urlunsplit(
|
url = urllib.parse.urlunsplit(("https", domain, "/api/v1/custom_emojis", "", ""))
|
||||||
("https", domain, "/api/v1/custom_emojis", "", "")
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
except requests.exceptions.RequestException:
|
except requests.exceptions.RequestException:
|
||||||
|
@ -61,14 +62,18 @@ def emojo(domain):
|
||||||
categories = defaultdict(list)
|
categories = defaultdict(list)
|
||||||
for emoji in sorted(
|
for emoji in sorted(
|
||||||
response.json(),
|
response.json(),
|
||||||
# sort by category, then name within each category, then disambiguate by capitalization
|
# sort by category,
|
||||||
|
# then name within each category,
|
||||||
|
# then disambiguate by capitalization
|
||||||
key=lambda x: (x.get("category", ""), x["shortcode"].lower(), x["shortcode"]),
|
key=lambda x: (x.get("category", ""), x["shortcode"].lower(), x["shortcode"]),
|
||||||
):
|
):
|
||||||
if not show_all and not emoji.get("visible_in_picker", True):
|
if not show_all and not emoji.get("visible_in_picker", True):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
url = emoji["url" if show_animated else "static_url"]
|
url = emoji["url" if show_animated else "static_url"]
|
||||||
categories[emoji.get("category")].append(Emoj(shortcode=emoji["shortcode"], url=url))
|
categories[emoji.get("category")].append(
|
||||||
|
Emoj(shortcode=emoji["shortcode"], url=url)
|
||||||
|
)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"emojo.html", domain=domain, categories=categories, show_animated=show_animated
|
"emojo.html", domain=domain, categories=categories, show_animated=show_animated
|
||||||
|
|
Loading…
Reference in New Issue