Skip to content

Commit

Permalink
Minor Refactoring (#101)
Browse files Browse the repository at this point in the history
* Fix conditional so it checks *both* criteria.
* Refactor and add some error handling
  • Loading branch information
bpepple authored Mar 3, 2024
1 parent 3f3f9ed commit f363399
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions metrontagger/talker.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,22 @@ def _get_source_id(md: Metadata) -> tuple[InfoSource, int | None]:
lower_notes = md.notes.lower()
if "metrontagger" in lower_notes:
source = InfoSource.metron
id_ = int(md.notes.split("issue_id:")[1].strip("]"))
try:
id_ = int(md.notes.split("issue_id:")[1].strip("]"))
except ValueError:
LOGGER.error("Comic has invalid id: %s #%s", md.series.name, md.issue)
return source, id_
if "comictagger" in lower_notes:
if "metron" in lower_notes:
source = InfoSource.metron
id_ = int(md.notes.split("Issue ID")[1].strip(" ").strip("]"))
if "comic vine" in lower_notes:
elif "comic vine" in lower_notes:
source = InfoSource.comic_vine
else:
source = InfoSource.unknown
try:
id_ = int(md.notes.split("Issue ID")[1].strip(" ").strip("]"))

except ValueError:
LOGGER.error("Comic has invalid id: %s #%s", md.series.name, md.issue)
return source, id_

def _process_file(
Expand All @@ -158,7 +164,7 @@ def _process_file(
if ca.has_metadata():
md = ca.read_metadata()
source, id_ = self._get_source_id(md)
if source is not InfoSource.unknown or id_ is not None:
if source is not InfoSource.unknown and id_ is not None:
match source:
case InfoSource.metron:
questionary.print(
Expand Down

0 comments on commit f363399

Please sign in to comment.