From 6452fbde1dcb5ca076490a6b1982701dfbb89849 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 27 Jul 2023 08:34:48 -0700 Subject: feat(html): position lowest unread at top --- src/due/html.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'src') 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"\[(\d+)<\/a>\]", element) + available_matches = re.search(r"\[(\d+)<\/a>\]", element) + read_matches = re.search(r"\[(?=\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'
  • {title} {progress} [{available}]
  • ' ) - current_html = sorted(current_html, key=seen, reverse=True) + current_html = sorted(current_html, key=seen) current_html.insert(0, "
      ") current_html.append("
    ") @@ -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, "
      ") current_html.append("
    ") -- cgit v1.2.3