Skip to content

Commit

Permalink
Minor fix when creating Comic object.
Browse files Browse the repository at this point in the history
  • Loading branch information
bpepple committed Oct 11, 2023
1 parent 4062218 commit 89bbc49
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions metrontagger/talker.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _process_file(
fn: Path,
interactive: bool,
) -> tuple[Optional[int], bool]:
ca = Comic(fn)
ca = Comic(str(fn))

if not ca.is_writable() and not ca.seems_to_be_a_comic_archive():
questionary.print(
Expand Down Expand Up @@ -175,19 +175,20 @@ def _write_issue_md(self: "Talker", filename: Path, issue_id: int) -> None:
# sourcery skip: extract-method, inline-immediately-returned-variable
success = False
resp = None
md = None
try:
resp = self.api.issue(issue_id)
except ApiError as e:
questionary.print(f"Failed to retrieve data: {e!r}", style=Styles.ERROR)
if resp is not None:
ca = Comic(filename)
ca = Comic(str(filename))
meta_data = Metadata()
meta_data.set_default_page_list(ca.get_number_of_pages())
md = self._map_resp_to_metadata(resp)
md.overlay(meta_data)
success = ca.write_metadata(md)

if success:
if success and md is not None:
questionary.print(
f"Using '{md.series.name} #{md.issue} ({md.cover_date.year})' metadata for "
f"'{filename.name}'.",
Expand All @@ -211,7 +212,7 @@ def identify_comics(

for fn in file_list:
if config.ignore_existing:
comic_archive = Comic(fn)
comic_archive = Comic(str(fn))
if comic_archive.has_metadata():
questionary.print(
f"{fn.name} has metadata. Skipping...",
Expand Down Expand Up @@ -245,18 +246,18 @@ def create_note(issue_id: int) -> str:
)

def add_credits_to_metadata(
md: Metadata,
meta_data: Metadata,
credits_resp: list[CreditsSchema],
) -> Metadata:
def create_role_list(roles: list[RolesSchema]) -> list[Role]:
return [Role(r.name, r.id) for r in roles]

for c in credits_resp:
if c.role:
md.add_credit(Credit(c.creator, create_role_list(c.role), c.id))
meta_data.add_credit(Credit(c.creator, create_role_list(c.role), c.id))
else:
md.add_credit(Credit(c.creator, [], c.id))
return md
meta_data.add_credit(Credit(c.creator, [], c.id))
return meta_data

def map_ratings(rating: str) -> str:
age_rating = rating.lower()
Expand Down

0 comments on commit 89bbc49

Please sign in to comment.