diff options
| author | Fuwn <[email protected]> | 2023-07-25 16:12:43 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-07-25 16:12:43 -0700 |
| commit | dd726170c19e3d062c4da11423bffdf61edb671e (patch) | |
| tree | 3013772309c7c173804560ee69e4b1a9df6dee6f /src | |
| parent | fix(html): fix anime id cases (diff) | |
| download | old.due.moe-dd726170c19e3d062c4da11423bffdf61edb671e.tar.xz old.due.moe-dd726170c19e3d062c4da11423bffdf61edb671e.zip | |
feat(html): sort lists
Diffstat (limited to 'src')
| -rw-r--r-- | src/due/html.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/due/html.py b/src/due/html.py index eba7e8b..0cc4c74 100644 --- a/src/due/html.py +++ b/src/due/html.py @@ -3,10 +3,20 @@ import joblib from due.cache import cache from flask import request import math +import re + + +def seen(element): + match = re.search(r"\s(\d+)\s", element) + + if match: + return int(match.group(1)) + else: + return 0 def anime_to_html(releasing_outdated_anime): - current_html = "<ul>" + current_html = [] ids = [] for media in releasing_outdated_anime: @@ -32,13 +42,20 @@ def anime_to_html(releasing_outdated_anime): if title is None: title = anime["title"]["romaji"] - current_html += f'<li><a href="https://anilist.co/anime/{id}" target="_blank">{title}</a> {progress} [{available}]</li>' + current_html.append( + f'<li><a href="https://anilist.co/anime/{id}" target="_blank">{title}</a> {progress} [{available}]</li>' + ) + + current_html = sorted(current_html, key=seen, reverse=True) - return (current_html + "</ul>", len(ids)) + current_html.insert(0, "<ul>") + current_html.append("</ul>") + + return ("".join(current_html), len(ids)) def manga_to_html(releasing_outdated_manga): - current_html = ["<ul>"] + current_html = [] ids = [] def process(media): @@ -162,6 +179,9 @@ def manga_to_html(releasing_outdated_manga): joblib.delayed(process)(media) for media in releasing_outdated_manga ) + current_html = sorted(current_html, key=seen, reverse=True) + + current_html.insert(0, "<ul>") current_html.append("</ul>") return ("".join(current_html), len(ids)) |