Skip to content

Commit

Permalink
Merge pull request #29 from mizaki/warn_multi_nn
Browse files Browse the repository at this point in the history
Log duplicate issue numbers for a series and return all results
  • Loading branch information
mizaki authored Aug 10, 2024
2 parents 62fc0b8 + ce5138a commit 47cb6c7
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions gcd_talker/gcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ def fetch_issues_in_series(self, series_id: str) -> list[GenericMetadata]:
"ELSE NULL END, '\n') AS 'story_titles' "
"FROM gcd_issue "
"LEFT JOIN gcd_story ON gcd_story.issue_id = gcd_issue.id AND gcd_story.type_id = 19 "
"WHERE gcd_issue.series_id = ? "
"GROUP BY gcd_issue.number;",
"WHERE gcd_issue.series_id = ? AND gcd_issue.variant_of_id IS NULL "
"GROUP BY gcd_issue.id;",
[int(series_id)],
)
rows = cur.fetchall()
Expand Down Expand Up @@ -487,14 +487,14 @@ def fetch_issues_by_series_issue_num_and_year(
gcd_story.title END, '\n') AS 'story_titles'
FROM gcd_issue
LEFT JOIN gcd_story ON gcd_story.issue_id=gcd_issue.id AND gcd_story.type_id=19
WHERE gcd_issue.series_id=? """
WHERE gcd_issue.series_id=? AND gcd_issue.variant_of_id IS NULL """

sql_search_issues: str = "AND gcd_issue.number=? AND (gcd_issue.key_date LIKE ? OR gcd_issue.key_date='') "

sql_search_issues_nn: str = """AND (gcd_issue.number=? OR gcd_issue.number='[nn]') AND
(gcd_issue.key_date LIKE ? OR gcd_issue.key_date='') """

sql_search_group: str = "GROUP BY gcd_issue.number;"
sql_search_group: str = "GROUP BY gcd_issue.id;"

if self.nn_is_issue_one and issue_number == "1":
sql_search = sql_search_main + sql_search_issues_nn + sql_search_group
Expand Down Expand Up @@ -829,8 +829,7 @@ def _fetch_issue_data(self, series_id: int, issue_number: str) -> GenericMetadat
# Find the id of the issue and pass it along

sql_query: str = ""
sql_base: str = """SELECT gcd_issue.id AS 'id'
FROM gcd_issue """
sql_base: str = "SELECT gcd_issue.id AS 'id' FROM gcd_issue "
sql_where: str = "WHERE gcd_issue.series_id=? AND gcd_issue.number=?"
sql_where_nn: str = "WHERE gcd_issue.series_id=? AND (gcd_issue.number=? OR gcd_issue.number='[nn]')"

Expand All @@ -849,10 +848,18 @@ def _fetch_issue_data(self, series_id: int, issue_number: str) -> GenericMetadat
sql_query,
[series_id, issue_number],
)
row = cur.fetchone()

if row["id"]:
return self._fetch_issue_data_by_issue_id(row["id"])
row = cur.fetchall()

# Expect one result however there are exception: "nn" for issue number and new volumes restarting issue
# number back to 1 are possible therefore, take the first result and log the remainder
if len(row) > 1:
logger.warning(
f"More than ONE issue found for: Series ID: {series_id}, Issue Number: "
f"{issue_number}. Using first result.\n"
f"All result IDs: {', '.join([str(i_id['id']) for i_id in row])}"
)
if row[0]["id"]:
return self._fetch_issue_data_by_issue_id(row[0]["id"])

except sqlite3.DataError as e:
logger.debug(f"DB data error: {e}")
Expand Down

0 comments on commit 47cb6c7

Please sign in to comment.