Account for aliases field from CV
This commit is contained in:
parent
e6414fba96
commit
c0880c9afe
@ -84,7 +84,8 @@ class ComicCacher:
|
||||
+ "image_url TEXT,"
|
||||
+ "description TEXT,"
|
||||
+ "timestamp DATE DEFAULT (datetime('now','localtime')),"
|
||||
+ "source_name TEXT NOT NULL)"
|
||||
+ "source_name TEXT NOT NULL,"
|
||||
+ "aliases TEXT)" # Newline separated
|
||||
)
|
||||
|
||||
cur.execute(
|
||||
@ -96,6 +97,7 @@ class ComicCacher:
|
||||
+ "start_year INT,"
|
||||
+ "timestamp DATE DEFAULT (datetime('now','localtime')), "
|
||||
+ "source_name TEXT NOT NULL,"
|
||||
+ "aliases TEXT," # Newline separated
|
||||
+ "PRIMARY KEY (id, source_name))"
|
||||
)
|
||||
|
||||
@ -105,6 +107,7 @@ class ComicCacher:
|
||||
+ "url_list TEXT,"
|
||||
+ "timestamp DATE DEFAULT (datetime('now','localtime')), "
|
||||
+ "source_name TEXT NOT NULL,"
|
||||
+ "aliases TEXT," # Newline separated
|
||||
+ "PRIMARY KEY (issue_id, source_name))"
|
||||
)
|
||||
|
||||
@ -121,6 +124,7 @@ class ComicCacher:
|
||||
+ "description TEXT,"
|
||||
+ "timestamp DATE DEFAULT (datetime('now','localtime')), "
|
||||
+ "source_name TEXT NOT NULL,"
|
||||
+ "aliases TEXT," # Newline separated
|
||||
+ "PRIMARY KEY (id, source_name))"
|
||||
)
|
||||
|
||||
@ -153,8 +157,8 @@ class ComicCacher:
|
||||
|
||||
cur.execute(
|
||||
"INSERT INTO VolumeSearchCache "
|
||||
+ "(source_name, search_term, id, name, start_year, publisher, count_of_issues, image_url, description) "
|
||||
+ "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
+ "(source_name, search_term, id, name, start_year, publisher, count_of_issues, image_url, description, aliases) "
|
||||
+ "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(
|
||||
source_name,
|
||||
search_term.casefold(),
|
||||
@ -165,6 +169,7 @@ class ComicCacher:
|
||||
record["count_of_issues"],
|
||||
url,
|
||||
record["description"],
|
||||
record["aliases"],
|
||||
),
|
||||
)
|
||||
|
||||
@ -197,6 +202,7 @@ class ComicCacher:
|
||||
"description": record[7],
|
||||
"publisher": {"name": record[4]},
|
||||
"image": {"super_url": record[6]},
|
||||
"aliases": record[10],
|
||||
}
|
||||
)
|
||||
|
||||
@ -268,6 +274,7 @@ class ComicCacher:
|
||||
"count_of_issues": cv_volume_record["count_of_issues"],
|
||||
"start_year": cv_volume_record["start_year"],
|
||||
"timestamp": timestamp,
|
||||
"aliases": cv_volume_record["aliases"],
|
||||
}
|
||||
self.upsert(cur, "volumes", data)
|
||||
|
||||
@ -295,6 +302,7 @@ class ComicCacher:
|
||||
"thumb_url": issue["image"]["thumb_url"],
|
||||
"description": issue["description"],
|
||||
"timestamp": timestamp,
|
||||
"aliases": issue["aliases"],
|
||||
}
|
||||
self.upsert(cur, "issues", data)
|
||||
|
||||
@ -313,7 +321,8 @@ class ComicCacher:
|
||||
|
||||
# fetch
|
||||
cur.execute(
|
||||
"SELECT source_name,id,name,publisher,count_of_issues,start_year FROM Volumes WHERE id=? AND source_name=?",
|
||||
"SELECT source_name,id,name,publisher,count_of_issues,start_year,aliases FROM Volumes"
|
||||
" WHERE id=? AND source_name=?",
|
||||
[volume_id, source_name],
|
||||
)
|
||||
|
||||
@ -330,6 +339,7 @@ class ComicCacher:
|
||||
"count_of_issues": row[4],
|
||||
"start_year": row[5],
|
||||
"publisher": {"name": row[3]},
|
||||
"aliases": row[6],
|
||||
}
|
||||
)
|
||||
|
||||
@ -352,7 +362,7 @@ class ComicCacher:
|
||||
|
||||
cur.execute(
|
||||
(
|
||||
"SELECT source_name,id,name,issue_number,site_detail_url,cover_date,super_url,thumb_url,description"
|
||||
"SELECT source_name,id,name,issue_number,site_detail_url,cover_date,super_url,thumb_url,description,aliases"
|
||||
" FROM Issues WHERE volume_id=? AND source_name=?"
|
||||
),
|
||||
[volume_id, source_name],
|
||||
@ -370,6 +380,7 @@ class ComicCacher:
|
||||
"cover_date": row[5],
|
||||
"image": {"super_url": row[6], "thumb_url": row[7]},
|
||||
"description": row[8],
|
||||
"aliases": row[9],
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -298,7 +298,17 @@ class ComicVineTalker:
|
||||
if not literal:
|
||||
# Remove any search results that don't contain all the search terms (iterate backwards for easy removal)
|
||||
for record in reversed(search_results):
|
||||
if not utils.titles_match(search_series_name, record["name"]):
|
||||
matched = False
|
||||
aliases = []
|
||||
if record["aliases"]:
|
||||
aliases = record["aliases"].split("\n")
|
||||
aliases.append(record["name"])
|
||||
|
||||
for name in aliases:
|
||||
if utils.titles_match(search_series_name, name):
|
||||
matched = True
|
||||
break
|
||||
if not matched:
|
||||
search_results.remove(record)
|
||||
|
||||
# Cache these search results, even if it's literal we cache the results
|
||||
@ -321,7 +331,7 @@ class ComicVineTalker:
|
||||
params = {
|
||||
"api_key": self.api_key,
|
||||
"format": "json",
|
||||
"field_list": "name,id,start_year,publisher,count_of_issues",
|
||||
"field_list": "name,id,start_year,publisher,count_of_issues,aliases",
|
||||
}
|
||||
cv_response = self.get_cv_content(volume_url, params)
|
||||
|
||||
@ -344,7 +354,7 @@ class ComicVineTalker:
|
||||
"api_key": self.api_key,
|
||||
"filter": "volume:" + str(series_id),
|
||||
"format": "json",
|
||||
"field_list": "id,volume,issue_number,name,image,cover_date,site_detail_url,description",
|
||||
"field_list": "id,volume,issue_number,name,image,cover_date,site_detail_url,description,aliases",
|
||||
"offset": 0,
|
||||
}
|
||||
cv_response = self.get_cv_content(self.api_base_url + "/issues/", params)
|
||||
@ -388,7 +398,7 @@ class ComicVineTalker:
|
||||
params: dict[str, str | int] = {
|
||||
"api_key": self.api_key,
|
||||
"format": "json",
|
||||
"field_list": "id,volume,issue_number,name,image,cover_date,site_detail_url,description",
|
||||
"field_list": "id,volume,issue_number,name,image,cover_date,site_detail_url,description,aliases",
|
||||
"filter": flt,
|
||||
}
|
||||
|
||||
|
@ -93,6 +93,7 @@ class CVIssuesResults(TypedDict):
|
||||
name: str
|
||||
site_detail_url: str
|
||||
volume: NotRequired[CVVolume]
|
||||
aliases: str
|
||||
|
||||
|
||||
class CVPublisher(TypedDict, total=False):
|
||||
@ -110,6 +111,7 @@ class CVVolumeResults(TypedDict):
|
||||
publisher: CVPublisher
|
||||
start_year: str
|
||||
resource_type: NotRequired[str]
|
||||
aliases: NotRequired[str | None]
|
||||
|
||||
|
||||
class CVCredits(TypedDict):
|
||||
|
@ -15,6 +15,7 @@ search_results = [
|
||||
name="test",
|
||||
publisher=comictaggerlib.resulttypes.CVPublisher(name="test"),
|
||||
start_year="", # This is currently submitted as a string and returned as an int
|
||||
aliases=None,
|
||||
),
|
||||
comictaggerlib.resulttypes.CVVolumeResults(
|
||||
count_of_issues=1,
|
||||
@ -24,6 +25,7 @@ search_results = [
|
||||
name="test 2",
|
||||
publisher=comictaggerlib.resulttypes.CVPublisher(name="test"),
|
||||
start_year="", # This is currently submitted as a string and returned as an int
|
||||
aliases=None,
|
||||
),
|
||||
]
|
||||
|
||||
|
@ -98,6 +98,7 @@ cv_volume_result: dict[str, Any] = {
|
||||
"count_of_issues": 6,
|
||||
"id": 23437,
|
||||
"name": "Cory Doctorow's Futuristic Tales of the Here and Now",
|
||||
"aliases": None,
|
||||
"publisher": {
|
||||
"api_detail_url": "https://comicvine.gamespot.com/api/publisher/4010-1190/",
|
||||
"id": 1190,
|
||||
|
@ -39,7 +39,7 @@ def test_fetch_issues_by_volume_issue_num_and_year(comicvine_api):
|
||||
cv_expected = testing.comicvine.cv_issue_result["results"].copy()
|
||||
testing.comicvine.filter_field_list(
|
||||
cv_expected,
|
||||
{"params": {"field_list": "id,volume,issue_number,name,image,cover_date,site_detail_url,description"}},
|
||||
{"params": {"field_list": "id,volume,issue_number,name,image,cover_date,site_detail_url,description,aliases"}},
|
||||
)
|
||||
assert cv[0] == cv_expected
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user