diff options
| author | Fuwn <[email protected]> | 2023-07-27 08:34:48 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-07-27 08:34:48 -0700 |
| commit | 6452fbde1dcb5ca076490a6b1982701dfbb89849 (patch) | |
| tree | 598c6a610c2f6b8bffad064d7a0b8f7711019298 /src | |
| parent | fix(html): a ton of edge case handling (diff) | |
| download | old.due.moe-6452fbde1dcb5ca076490a6b1982701dfbb89849.tar.xz old.due.moe-6452fbde1dcb5ca076490a6b1982701dfbb89849.zip | |
feat(html): position lowest unread at top
Diffstat (limited to 'src')
| -rw-r--r-- | src/due/html.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/due/html.py b/src/due/html.py index 3c9fdbf..c06f939 100644 --- a/src/due/html.py +++ b/src/due/html.py @@ -8,20 +8,31 @@ import os def seen(element, manga=False): - matches = re.findall(r"\d+\]|\[\d+", element) + read = 0 if manga: - matches = re.search(r"\[<a.*?>(\d+)<\/a>\]", element) + available_matches = re.search(r"\[<a.*?>(\d+)<\/a>\]", element) + read_matches = re.search(r"\[<a.*?>(?=\d+)<\/a>\]", element) - if matches: - return int(matches.group(1)) + if read_matches: + read = int(read_matches.group()) + print(read) + + if available_matches: + return int(available_matches.group(1)) - read else: return 0 - if len(matches) > 1: - return int(matches[1].strip("[]")) - elif len(matches) == 1: - return int(matches[0].strip("[]")) + available_matches = re.findall(r"\d+\]|\[\d+", element) + read_matches = re.search(r"\s(\d+)\s", element) + + if read_matches: + read = int(read_matches.group(1)) + + if len(available_matches) > 1: + return int(available_matches[1].strip("[]")) - read + elif len(available_matches) == 1: + return int(available_matches[0].strip("[]")) - read else: return 0 @@ -62,7 +73,7 @@ def anime_to_html(releasing_outdated_anime): 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) + current_html = sorted(current_html, key=seen) current_html.insert(0, "<ul>") current_html.append("</ul>") @@ -218,7 +229,7 @@ def manga_to_html(releasing_outdated_manga, show_missing): joblib.delayed(process)(media) for media in releasing_outdated_manga ) - current_html = sorted(current_html, key=lambda x: seen(x, manga=True), reverse=True) + current_html = sorted(current_html, key=lambda x: seen(x, manga=True)) current_html.insert(0, "<ul>") current_html.append("</ul>") |