Skip to content

Commit

Permalink
Refactor unwatched to stop repeating messages
Browse files Browse the repository at this point in the history
  • Loading branch information
s-t-e-v-e-n-k committed Aug 18, 2023
1 parent b0a162e commit 3143e83
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
12 changes: 6 additions & 6 deletions jellyash/unwatched.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from .search import search_single_show


def ending(count):
return "s" if count != 1 else ""
def pluralized_str(count: int, prefix: str = "un") -> str:
return f"{count} {prefix}watched episode{'s' if count != 1 else ''}"


def unwatched() -> None:
Expand All @@ -27,9 +27,9 @@ def all_unwatched(client) -> None:
total = 0
for series in sorted(r, key=attrgetter("Name")):
if (count := series.UserData.UnplayedItemCount) > 0:
print(f"{series.Name}: {count} unwatched episode{ending(count)}")
print(f"{series.Name}: {pluralized_str(count)}")
total += count
print(f"Total: {total} unwatched episode{ending(total)}")
print(f"Total: {pluralized_str(total)}")


def specific_unwatched(client, term: str) -> None:
Expand All @@ -41,5 +41,5 @@ def specific_unwatched(client, term: str) -> None:
unwatched = show.UserData.UnplayedItemCount
total = sum(s.ChildCount for s in client.jellyfin.get_seasons(show.Id))
count = total - unwatched
print(f"{show.Name}: {count} watched episode{ending(count)}")
print(f"{show.Name}: {unwatched} unwatched episode{ending(unwatched)}")
print(f"{show.Name}: {pluralized_str(count, prefix='')}")
print(f"{show.Name}: {pluralized_str(unwatched)}")
15 changes: 9 additions & 6 deletions tests/test_unwatched.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@

from jellyash.unwatched import (
all_unwatched,
ending,
pluralized_str,
specific_unwatched,
unwatched,
)

from .conftest import ClientTest


class TestEnding(unittest.TestCase):
def test_ending(self):
self.assertEqual("s", ending(0))
self.assertEqual("", ending(1))
self.assertEqual("s", ending(2))
class TestPluralizedStr(unittest.TestCase):
def test_pluralized_str(self):
self.assertEqual("0 unwatched episodes", pluralized_str(0))
self.assertEqual("1 unwatched episode", pluralized_str(1))
self.assertEqual("2 unwatched episodes", pluralized_str(2))
self.assertEqual(
"1 dewatched episode", pluralized_str(1, prefix="de")
)


class TestUnwatched(ClientTest):
Expand Down

0 comments on commit 3143e83

Please sign in to comment.