Include CMC and Mana Cost in card data
This commit is contained in:
parent
0731bf8429
commit
14e5ddaa24
6 changed files with 16 additions and 3 deletions
|
@ -34,6 +34,7 @@ CREATE TABLE IF NOT EXISTS "oracle" (
|
||||||
"name" TEXT NOT NULL,
|
"name" TEXT NOT NULL,
|
||||||
"color_identity" TEXT NOT NULL,
|
"color_identity" TEXT NOT NULL,
|
||||||
"cmc" DECIMAL(10, 2) NOT NULL,
|
"cmc" DECIMAL(10, 2) NOT NULL,
|
||||||
|
"mana_cost" TEXT,
|
||||||
"type_line" TEXT NOT NULL,
|
"type_line" TEXT NOT NULL,
|
||||||
"edhrec_rank" INTEGER,
|
"edhrec_rank" INTEGER,
|
||||||
"oracle_text" TEXT,
|
"oracle_text" TEXT,
|
||||||
|
@ -139,6 +140,7 @@ SELECT "oracle"."oracle_id"
|
||||||
, "oracle"."name"
|
, "oracle"."name"
|
||||||
, "oracle"."color_identity"
|
, "oracle"."color_identity"
|
||||||
, "oracle"."cmc"
|
, "oracle"."cmc"
|
||||||
|
, "oracle"."mana_cost"
|
||||||
, "oracle"."type_line"
|
, "oracle"."type_line"
|
||||||
, "oracle"."edhrec_rank"
|
, "oracle"."edhrec_rank"
|
||||||
, "oracle"."oracle_text"
|
, "oracle"."oracle_text"
|
||||||
|
@ -156,6 +158,7 @@ SELECT "oracle"."oracle_id"
|
||||||
, "oracle"."name"
|
, "oracle"."name"
|
||||||
, "oracle"."color_identity"
|
, "oracle"."color_identity"
|
||||||
, "oracle"."cmc"
|
, "oracle"."cmc"
|
||||||
|
, "oracle"."mana_cost"
|
||||||
, "oracle"."type_line"
|
, "oracle"."type_line"
|
||||||
, "oracle"."edhrec_rank"
|
, "oracle"."edhrec_rank"
|
||||||
, "oracle"."oracle_text"
|
, "oracle"."oracle_text"
|
||||||
|
|
|
@ -253,6 +253,7 @@ def update_scryfall(ctx, filename):
|
||||||
, "name"
|
, "name"
|
||||||
, "color_identity"
|
, "color_identity"
|
||||||
, "cmc"
|
, "cmc"
|
||||||
|
, "mana_cost"
|
||||||
, "type_line"
|
, "type_line"
|
||||||
, "edhrec_rank"
|
, "edhrec_rank"
|
||||||
, "oracle_text"
|
, "oracle_text"
|
||||||
|
@ -263,6 +264,7 @@ def update_scryfall(ctx, filename):
|
||||||
, "name" = "excluded"."name"
|
, "name" = "excluded"."name"
|
||||||
, "color_identity" = "excluded"."color_identity"
|
, "color_identity" = "excluded"."color_identity"
|
||||||
, "cmc" = "excluded"."cmc"
|
, "cmc" = "excluded"."cmc"
|
||||||
|
, "mana_cost" = "excluded"."mana_cost"
|
||||||
, "type_line" = "excluded"."type_line"
|
, "type_line" = "excluded"."type_line"
|
||||||
, "edhrec_rank" = "excluded"."edhrec_rank"
|
, "edhrec_rank" = "excluded"."edhrec_rank"
|
||||||
, "oracle_text" = "excluded"."oracle_text"
|
, "oracle_text" = "excluded"."oracle_text"
|
||||||
|
|
|
@ -260,11 +260,12 @@ async def store_card(db: psycopg.Cursor, card: tutor.models.Card) -> None:
|
||||||
"""
|
"""
|
||||||
INSERT INTO tmp_cards
|
INSERT INTO tmp_cards
|
||||||
("scryfall_id", "oracle_id", "name", "set_code", "collector_number",
|
("scryfall_id", "oracle_id", "name", "set_code", "collector_number",
|
||||||
"rarity", "color_identity", "cmc", "type_line", "release_date",
|
"rarity", "color_identity", "cmc", "mana_cost", "type_line",
|
||||||
"edhrec_rank", "oracle_text")
|
"release_date", "edhrec_rank", "oracle_text")
|
||||||
VALUES (%(scryfall_id)s, %(oracle_id)s, %(name)s, %(set_code)s,
|
VALUES (%(scryfall_id)s, %(oracle_id)s, %(name)s, %(set_code)s,
|
||||||
%(collector_number)s, %(rarity)s, %(color_identity)s, %(cmc)s,
|
%(collector_number)s, %(rarity)s, %(color_identity)s, %(cmc)s,
|
||||||
%(type_line)s, %(release_date)s, %(edhrec_rank)s, %(oracle_text)s)
|
%(mana_cost)s, %(type_line)s, %(release_date)s, %(edhrec_rank)s,
|
||||||
|
%(oracle_text)s)
|
||||||
""",
|
""",
|
||||||
{
|
{
|
||||||
"scryfall_id": str(card.scryfall_id),
|
"scryfall_id": str(card.scryfall_id),
|
||||||
|
@ -275,6 +276,7 @@ async def store_card(db: psycopg.Cursor, card: tutor.models.Card) -> None:
|
||||||
"rarity": str(card.rarity),
|
"rarity": str(card.rarity),
|
||||||
"color_identity": tutor.models.Color.to_string(card.color_identity),
|
"color_identity": tutor.models.Color.to_string(card.color_identity),
|
||||||
"cmc": str(card.cmc),
|
"cmc": str(card.cmc),
|
||||||
|
"mana_cost": card.mana_cost,
|
||||||
"type_line": card.type_line,
|
"type_line": card.type_line,
|
||||||
"release_date": str(card.release_date) if card.release_date else None,
|
"release_date": str(card.release_date) if card.release_date else None,
|
||||||
"edhrec_rank": card.edhrec_rank,
|
"edhrec_rank": card.edhrec_rank,
|
||||||
|
|
|
@ -71,6 +71,7 @@ class OracleCard:
|
||||||
type_line: str
|
type_line: str
|
||||||
games: typing.Set[Game]
|
games: typing.Set[Game]
|
||||||
legalities: typing.Dict[str, Legality]
|
legalities: typing.Dict[str, Legality]
|
||||||
|
mana_cost: typing.Optional[str] = None
|
||||||
edhrec_rank: typing.Optional[int] = None
|
edhrec_rank: typing.Optional[int] = None
|
||||||
oracle_text: typing.Optional[str] = None
|
oracle_text: typing.Optional[str] = None
|
||||||
|
|
||||||
|
@ -89,6 +90,7 @@ class Card:
|
||||||
release_date: datetime.date
|
release_date: datetime.date
|
||||||
games: typing.Set[Game]
|
games: typing.Set[Game]
|
||||||
legalities: typing.Dict[str, Legality]
|
legalities: typing.Dict[str, Legality]
|
||||||
|
mana_cost: typing.Optional[str] = None
|
||||||
edhrec_rank: typing.Optional[int] = None
|
edhrec_rank: typing.Optional[int] = None
|
||||||
oracle_text: typing.Optional[str] = None
|
oracle_text: typing.Optional[str] = None
|
||||||
price_usd: typing.Optional[decimal.Decimal] = None
|
price_usd: typing.Optional[decimal.Decimal] = None
|
||||||
|
|
|
@ -19,6 +19,7 @@ def to_card(data: dict) -> tutor.models.Card:
|
||||||
"".join(data.get("color_identity", []))
|
"".join(data.get("color_identity", []))
|
||||||
),
|
),
|
||||||
cmc=decimal.Decimal(data.get("cmc", "0")),
|
cmc=decimal.Decimal(data.get("cmc", "0")),
|
||||||
|
mana_cost=data.get("mana_cost"),
|
||||||
type_line=data.get("type_line", ""),
|
type_line=data.get("type_line", ""),
|
||||||
release_date=datetime.date.fromisoformat(data["released_at"])
|
release_date=datetime.date.fromisoformat(data["released_at"])
|
||||||
if "released_at" in data
|
if "released_at" in data
|
||||||
|
|
|
@ -60,6 +60,7 @@ class JSONEncoder(json.JSONEncoder):
|
||||||
"color_identity": tutor.models.Color.to_string(card.color_identity),
|
"color_identity": tutor.models.Color.to_string(card.color_identity),
|
||||||
"oracle_text": card.oracle_text,
|
"oracle_text": card.oracle_text,
|
||||||
"cmc": float(card.cmc),
|
"cmc": float(card.cmc),
|
||||||
|
"mana_cost": card.mana_cost,
|
||||||
"type_line": card.type_line,
|
"type_line": card.type_line,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +78,8 @@ class JSONEncoder(json.JSONEncoder):
|
||||||
"collector_number": card.collector_number,
|
"collector_number": card.collector_number,
|
||||||
"rarity": str(card.rarity),
|
"rarity": str(card.rarity),
|
||||||
"color_identity": tutor.models.Color.to_string(card.color_identity),
|
"color_identity": tutor.models.Color.to_string(card.color_identity),
|
||||||
|
"cmc": float(card.cmc),
|
||||||
|
"mana_cost": card.mana_cost,
|
||||||
"type_line": card.type_line,
|
"type_line": card.type_line,
|
||||||
"oracle_text": card.oracle_text,
|
"oracle_text": card.oracle_text,
|
||||||
"prices": {
|
"prices": {
|
||||||
|
|
Loading…
Reference in a new issue