Fix up full issue cache types.

This commit is contained in:
Mizaki 2022-10-29 01:33:42 +01:00
parent dcf853515c
commit a06d88efc0
3 changed files with 38 additions and 40 deletions

View File

@ -16,6 +16,7 @@
from __future__ import annotations
import datetime
import json
import logging
import os
import sqlite3 as lite
@ -229,11 +230,11 @@ class ComicCacher:
"timestamp": timestamp,
"aliases": issue["aliases"],
"alt_images_url": issue["alt_images_url"],
"characters": issue["characters"],
"locations": issue["locations"],
"teams": issue["teams"],
"story_arcs": issue["story_arcs"],
"credits": issue["credits"],
"characters": "\n".join(issue["characters"]),
"locations": "\n".join(issue["locations"]),
"teams": "\n".join(issue["teams"]),
"story_arcs": "\n".join(issue["story_arcs"]),
"credits": json.dumps(issue["credits"]),
"complete": issue["complete"],
}
self.upsert(cur, "issues", data)
@ -314,11 +315,11 @@ class ComicCacher:
volume=volume,
aliases=row[9],
alt_images_url=row[10],
characters=row[11],
locations=row[12],
credits=row[13],
teams=row[14],
story_arcs=row[15],
characters=row[11].split("\n"),
locations=row[12].split("\n"),
credits=json.loads(row[13]),
teams=row[14].split("\n"),
story_arcs=row[15].split("\n"),
complete=bool(row[16]),
)
@ -366,11 +367,11 @@ class ComicCacher:
volume=volume,
aliases=row[9],
alt_images_url=row[11],
characters=row[12],
locations=row[13],
credits=row[14],
teams=row[15],
story_arcs=row[16],
characters=row[12].split("\n"),
locations=row[13].split("\n"),
credits=json.loads(row[14]),
teams=row[15].split("\n"),
story_arcs=row[16].split("\n"),
complete=bool(row[17]),
)

View File

@ -3,6 +3,11 @@ from __future__ import annotations
from typing_extensions import Required, TypedDict
class Credits(TypedDict):
name: str
role: str
class ComicVolume(TypedDict, total=False):
aliases: str # Newline separated
count_of_issues: int
@ -26,9 +31,9 @@ class ComicIssue(TypedDict, total=False):
site_detail_url: str
volume: ComicVolume
alt_images_url: str # Comma separated URLs
characters: str # Newline separated
locations: str # Newline separated
credits: str # JSON: "{"name": "Bob Shakespeare", "role": "Writer"}"
teams: str # Newline separated
story_arcs: str # Newline separated
characters: list
locations: list
credits: list[Credits]
teams: list
story_arcs: list
complete: bool # Is the data complete? Includes characters, locations, credits.

View File

@ -34,7 +34,7 @@ from comicapi.issuestring import IssueString
from comictaggerlib import ctversion
from comictaggerlib.settings import ComicTaggerSettings
from comictalker.comiccacher import ComicCacher
from comictalker.resulttypes import ComicIssue, ComicVolume
from comictalker.resulttypes import ComicIssue, ComicVolume, Credits
from comictalker.talkerbase import (
ComicTalker,
SourceDetails,
@ -416,34 +416,27 @@ class ComicVineTalker(ComicTalker):
character_list = []
if record.get("character_credits"):
for char in record["character_credits"]:
# Convert to newline separated
character_list.append(char["name"])
characters = "\n".join(character_list)
location_list = []
if record.get("location_credits"):
for loc in record["location_credits"]:
location_list.append(loc["name"])
locations = "\n".join(location_list)
teams_list = []
if record.get("team_credits"):
for loc in record["team_credits"]:
teams_list.append(loc["name"])
teams = "\n".join(teams_list)
story_list = []
if record.get("story_arc_credits"):
for loc in record["story_arc_credits"]:
story_list.append(loc["name"])
storys = "\n".join(story_list)
persons_list = []
if record.get("person_credits"):
for person in record["person_credits"]:
persons_list.append({"name": person["name"], "role": person["role"]})
# Convert to JSON
persons = json.dumps(persons_list)
persons_list.append(Credits(name=person["name"], role=person["role"]))
formatted_results.append(
ComicIssue(
@ -458,11 +451,11 @@ class ComicVineTalker(ComicTalker):
site_detail_url=record.get("site_detail_url", ""),
volume=cast(ComicVolume, record["volume"]),
alt_images_url=alt_images_url,
characters=characters,
locations=locations,
teams=teams,
story_arcs=storys,
credits=persons,
characters=character_list,
locations=location_list,
teams=teams_list,
story_arcs=story_list,
credits=persons_list,
complete=complete,
)
)
@ -854,18 +847,17 @@ class ComicVineTalker(ComicTalker):
)
metadata.web_link = issue_results["site_detail_url"]
person_credits = json.loads(issue_results["credits"])
for person in person_credits:
for person in issue_results["credits"]:
if "role" in person:
roles = person["role"].split(",")
for role in roles:
# can we determine 'primary' from CV??
metadata.add_credit(person["name"], role.title().strip(), False)
metadata.characters = issue_results["characters"].replace("\n", ", ")
metadata.teams = issue_results["teams"].replace("\n", ", ")
metadata.locations = issue_results["locations"].replace("\n", ", ")
metadata.story_arc = issue_results["story_arcs"].replace("\n", ", ")
metadata.characters = ", ".join(issue_results["characters"])
metadata.teams = ", ".join(issue_results["teams"])
metadata.locations = ", ".join(issue_results["locations"])
metadata.story_arc = ", ".join(issue_results["story_arcs"])
return metadata