diff --git a/gcd_talker/gcd.py b/gcd_talker/gcd.py index bcc4a8d..758ab61 100644 --- a/gcd_talker/gcd.py +++ b/gcd_talker/gcd.py @@ -440,8 +440,8 @@ def fetch_issues_in_series(self, series_id: str) -> list[GenericMetadata]: cur.execute( "SELECT gcd_issue.id AS 'id', gcd_issue.number AS 'number', gcd_issue.key_date AS 'key_date'," " gcd_issue.title AS 'issue_title', gcd_issue.series_id AS 'series_id', " - "GROUP_CONCAT(CASE WHEN gcd_story.title IS NOT NULL AND gcd_story.title != '' THEN gcd_story.title " - "ELSE NULL END, '\n') AS 'story_titles' " + "GROUP_CONCAT(CASE WHEN gcd_story.title IS NOT NULL AND gcd_story.title != '' THEN " + "gcd_story.sequence_number || '::' || 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 = ? " @@ -484,7 +484,7 @@ def fetch_issues_by_series_issue_num_and_year( sql_search_main: str = """SELECT gcd_issue.id AS 'id', gcd_issue.key_date AS 'key_date', gcd_issue.number AS 'number', gcd_issue.title AS 'issue_title', gcd_issue.series_id AS 'series_id', GROUP_CONCAT(CASE WHEN gcd_story.title IS NOT NULL AND gcd_story.title != '' THEN - gcd_story.title END, '\n') AS 'story_titles' + gcd_story.sequence_number || '::' || 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=? """ @@ -539,6 +539,20 @@ def fetch_issues_by_series_issue_num_and_year( return results + def _split_issue_titles(self, concated_titles: str) -> list[str]: + titles_matrix: list[list[str]] = [] + if concated_titles: + titles = concated_titles.split("\n") + + for title in titles: + split_title = title.split("::") + titles_matrix.append([split_title[0], split_title[1]]) + titles_matrix.sort() + + return [title_mat[1] for title_mat in titles_matrix] + + return [] + def _match_format(self, string: str) -> str | None: # The publishing_format field is a free-text mess, try and make something useful word_list = [ @@ -717,11 +731,7 @@ def _format_gcd_issue(self, row: sqlite3.Row, complete: bool = False) -> GCDIssu number=row_dict["number"], issue_title=row_dict["issue_title"], series_id=row_dict["series_id"], - story_titles=( - row_dict["story_titles"].split("\n") - if "story_titles" in row_dict and row_dict["story_titles"] is not None - else [] - ), + story_titles=self._split_issue_titles(row_dict["story_titles"]), synopses=( row_dict["synopses"].split("\n\n") if "synopses" in row_dict and row_dict["synopses"] is not None @@ -902,7 +912,7 @@ def _fetch_issue_by_issue_id(self, issue_id: int) -> GCDIssue: "stddata_country.name AS 'country', stddata_country.code AS 'country_iso', " "stddata_language.name AS 'language', stddata_language.code AS 'language_iso', " "GROUP_CONCAT(CASE WHEN gcd_story.title IS NOT NULL AND gcd_story.title != '' THEN " - "gcd_story.title END, '\n') AS 'story_titles'," + "gcd_story.sequence_number || '::' || gcd_story.title END, '\n') AS 'story_titles'," "GROUP_CONCAT(CASE WHEN gcd_story.genre IS NOT NULL AND gcd_story.genre != '' THEN " "gcd_story.genre END, ';') AS 'genres'," "GROUP_CONCAT(CASE WHEN gcd_story.synopsis IS NOT NULL AND gcd_story.synopsis != '' THEN "