Compare commits
No commits in common. "82868b28c6d2704c909f03ed598ddce550bfdc03" and "4a0fc6e5398b6c1c6055401cca57104723b0221c" have entirely different histories.
82868b28c6
...
4a0fc6e539
5 changed files with 5 additions and 34 deletions
|
@ -1,4 +0,0 @@
|
||||||
ALTER TABLE "copies"
|
|
||||||
ADD COLUMN IF NOT EXISTS "external_id" TEXT UNIQUE;
|
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS "copies_external_id" ON "copies" ("external_id");
|
|
|
@ -242,15 +242,12 @@ def update_scryfall(ctx, filename):
|
||||||
try:
|
try:
|
||||||
card = tutor.scryfall.to_card(card_json).unwrap()
|
card = tutor.scryfall.to_card(card_json).unwrap()
|
||||||
await tutor.database.store_set(
|
await tutor.database.store_set(
|
||||||
cursor,
|
cursor, card_json["set"].upper(), card_json["set_name"]
|
||||||
card_json["set"].upper(),
|
|
||||||
card_json["set_type"],
|
|
||||||
card_json["set_name"],
|
|
||||||
)
|
)
|
||||||
await tutor.database.store_card(cursor, card)
|
await tutor.database.store_card(cursor, card)
|
||||||
await tutor.database.store_price(cursor, today, card)
|
await tutor.database.store_price(cursor, today, card)
|
||||||
except Exception as e:
|
except:
|
||||||
print(f"Skipping entry {card_json}: {e}")
|
print(f"Skipping entry {card_json}")
|
||||||
bar.update(read)
|
bar.update(read)
|
||||||
print("Updating oracle card data & indexes")
|
print("Updating oracle card data & indexes")
|
||||||
await cursor.execute(
|
await cursor.execute(
|
||||||
|
|
|
@ -36,7 +36,6 @@ async def load(
|
||||||
for row in reader:
|
for row in reader:
|
||||||
is_foil = "Foil" in row and row["Foil"].lower() == "foil"
|
is_foil = "Foil" in row and row["Foil"].lower() == "foil"
|
||||||
quantity = int(row.get("Quantity", row.get("Count", 1)))
|
quantity = int(row.get("Quantity", row.get("Count", 1)))
|
||||||
external_id = row.get("Delver Local ID")
|
|
||||||
if "Creation Date" in row:
|
if "Creation Date" in row:
|
||||||
created_date = arrow.get(
|
created_date = arrow.get(
|
||||||
row["Creation Date"].replace("_", " ")
|
row["Creation Date"].replace("_", " ")
|
||||||
|
@ -69,7 +68,6 @@ async def load(
|
||||||
language=row["Language"] or "English",
|
language=row["Language"] or "English",
|
||||||
collection=row.get("List name") or "Default",
|
collection=row.get("List name") or "Default",
|
||||||
created_date=created_date,
|
created_date=created_date,
|
||||||
external_id=external_id,
|
|
||||||
)
|
)
|
||||||
logging.info((quantity, card))
|
logging.info((quantity, card))
|
||||||
for i in range(quantity):
|
for i in range(quantity):
|
||||||
|
|
|
@ -351,26 +351,8 @@ async def store_set(
|
||||||
async def store_copy(db: psycopg.AsyncCursor, copy: tutor.models.CardCopy) -> None:
|
async def store_copy(db: psycopg.AsyncCursor, copy: tutor.models.CardCopy) -> None:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO copies ( "scryfall_id"
|
INSERT INTO copies ("scryfall_id", "isFoil", "collection", "condition", "created_date")
|
||||||
, "isFoil"
|
VALUES (%(scryfall_id)s, %(foil)s, %(collection)s, %(condition)s, %(created_date)s)
|
||||||
, "collection"
|
|
||||||
, "condition"
|
|
||||||
, "created_date"
|
|
||||||
, "external_id"
|
|
||||||
)
|
|
||||||
VALUES ( %(scryfall_id)s
|
|
||||||
, %(foil)s
|
|
||||||
, %(collection)s
|
|
||||||
, %(condition)s
|
|
||||||
, %(created_date)s
|
|
||||||
, %(external_id)s
|
|
||||||
)
|
|
||||||
ON CONFLICT ("external_id") DO UPDATE
|
|
||||||
SET "scryfall_id" = %(scryfall_id)s
|
|
||||||
, "isFoil" = %(foil)s
|
|
||||||
, "collection" = %(collection)s
|
|
||||||
, "condition" = %(condition)s
|
|
||||||
, "created_date" = %(created_date)s
|
|
||||||
""",
|
""",
|
||||||
{
|
{
|
||||||
"scryfall_id": str(copy.card.scryfall_id),
|
"scryfall_id": str(copy.card.scryfall_id),
|
||||||
|
@ -378,7 +360,6 @@ async def store_copy(db: psycopg.AsyncCursor, copy: tutor.models.CardCopy) -> No
|
||||||
"collection": copy.collection,
|
"collection": copy.collection,
|
||||||
"condition": copy.condition,
|
"condition": copy.condition,
|
||||||
"created_date": str(copy.created_date),
|
"created_date": str(copy.created_date),
|
||||||
"external_id": copy.external_id,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,6 @@ class CardCopy:
|
||||||
foil: bool
|
foil: bool
|
||||||
language: str = "English"
|
language: str = "English"
|
||||||
collection: str = "Default"
|
collection: str = "Default"
|
||||||
external_id: typing.Optional[str] = None
|
|
||||||
condition: typing.Optional[str] = None
|
condition: typing.Optional[str] = None
|
||||||
created_date: datetime.datetime = dataclasses.field(
|
created_date: datetime.datetime = dataclasses.field(
|
||||||
default_factory=datetime.datetime.now
|
default_factory=datetime.datetime.now
|
||||||
|
|
Loading…
Reference in a new issue