Skip to content

Commit 7bb6098

Browse files
committed
ep durations: default to zero if missing data
1 parent 0234266 commit 7bb6098

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

scripts/episode_durations.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DurationInfo(NamedTuple):
2323
title: str
2424
number_of_episodes: int
2525
duration_per_episode: int
26-
total_duration: Optional[int] # if there is no episode count, this will be None
26+
total_duration: int # if there is no episode count, this will be None
2727

2828

2929
OutputFormat = Literal["pprint", "csv", "json"]
@@ -55,16 +55,16 @@ def main(
5555
durations: List[DurationInfo] = []
5656

5757
for anime in anime_data:
58-
assert anime.APIList is not None
59-
assert anime.XMLData is not None
58+
assert (
59+
anime.APIList is not None
60+
), f"missing apilist data for id {anime.XMLData.anime_id}, update with `malexport update api-lists -u {username}`"
6061
assert anime.APIList.average_episode_duration is not None
6162

62-
if anime.XMLData.episodes is not None:
63-
total_duration = (
64-
anime.XMLData.episodes * anime.APIList.average_episode_duration
65-
)
66-
else:
67-
total_duration = None
63+
# default to 0 if theres no data
64+
# this makes sorting easier and can just remove rows later if needed
65+
total_duration = (anime.XMLData.episodes or 0) * (
66+
anime.APIList.average_episode_duration or 0
67+
)
6868

6969
durations.append(
7070
DurationInfo(

0 commit comments

Comments
 (0)