Add collection information
This commit is contained in:
parent
a90496bd0b
commit
e781bec46a
6 changed files with 67 additions and 44 deletions
|
@ -58,6 +58,7 @@ async def load(
|
||||||
card=found[0],
|
card=found[0],
|
||||||
foil=is_foil,
|
foil=is_foil,
|
||||||
language=row["Language"] or "English",
|
language=row["Language"] or "English",
|
||||||
|
collection=row.get("List name") or "Default",
|
||||||
)
|
)
|
||||||
logging.info((quantity, card))
|
logging.info((quantity, card))
|
||||||
for i in range(quantity):
|
for i in range(quantity):
|
||||||
|
|
|
@ -183,14 +183,14 @@ async def advanced_search(
|
||||||
]
|
]
|
||||||
if sort_by == "price":
|
if sort_by == "price":
|
||||||
orderings = [
|
orderings = [
|
||||||
"CAST(COALESCE(CASE WHEN \"copies\".\"isFoil\" THEN card_prices.usd_foil ELSE card_prices.usd END, 0) as decimal) DESC",
|
'CAST(COALESCE(CASE WHEN "copies"."isFoil" THEN card_prices.usd_foil ELSE card_prices.usd END, 0) as decimal) DESC',
|
||||||
*orderings,
|
*orderings,
|
||||||
]
|
]
|
||||||
params["last_update_key"] = "last_update"
|
params["last_update_key"] = "last_update"
|
||||||
query = " ".join(
|
query = " ".join(
|
||||||
[
|
[
|
||||||
"SELECT cards.*, card_prices.*",
|
"SELECT cards.*, card_prices.*, copies.*",
|
||||||
", CASE WHEN \"copies\".\"isFoil\" THEN card_prices.usd_foil",
|
', CASE WHEN "copies"."isFoil" THEN card_prices.usd_foil',
|
||||||
" ELSE card_prices.usd END AS usd",
|
" ELSE card_prices.usd END AS usd",
|
||||||
"FROM cards",
|
"FROM cards",
|
||||||
" ".join(joins),
|
" ".join(joins),
|
||||||
|
@ -212,26 +212,30 @@ async def advanced_search(
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return [
|
return [
|
||||||
tutor.models.Card(
|
tutor.models.CardCopy(
|
||||||
scryfall_id=row["scryfall_id"],
|
card=tutor.models.Card(
|
||||||
oracle_id=row["oracle_id"],
|
scryfall_id=row["scryfall_id"],
|
||||||
name=row["name"],
|
oracle_id=row["oracle_id"],
|
||||||
set_code=row["set_code"],
|
name=row["name"],
|
||||||
collector_number=row["collector_number"],
|
set_code=row["set_code"],
|
||||||
rarity=tutor.models.Rarity.from_string(row["rarity"]),
|
collector_number=row["collector_number"],
|
||||||
color_identity=tutor.models.Color.from_string(row["color_identity"]),
|
rarity=tutor.models.Rarity.from_string(row["rarity"]),
|
||||||
cmc=row["cmc"],
|
color_identity=tutor.models.Color.from_string(row["color_identity"]),
|
||||||
type_line=row["type_line"],
|
cmc=row["cmc"],
|
||||||
release_date=datetime.date.fromisoformat(row["release_date"]),
|
type_line=row["type_line"],
|
||||||
games=set(),
|
release_date=datetime.date.fromisoformat(row["release_date"]),
|
||||||
legalities={},
|
games=set(),
|
||||||
edhrec_rank=row["edhrec_rank"],
|
legalities={},
|
||||||
oracle_text=row["oracle_text"],
|
edhrec_rank=row["edhrec_rank"],
|
||||||
price_usd=convert_price(row["usd"]),
|
oracle_text=row["oracle_text"],
|
||||||
price_usd_foil=convert_price(row["usd_foil"]),
|
price_usd=convert_price(row["usd"]),
|
||||||
price_eur=convert_price(row["eur"]),
|
price_usd_foil=convert_price(row["usd_foil"]),
|
||||||
price_eur_foil=convert_price(row["eur_foil"]),
|
price_eur=convert_price(row["eur"]),
|
||||||
price_tix=convert_price(row["tix"]),
|
price_eur_foil=convert_price(row["eur_foil"]),
|
||||||
|
price_tix=convert_price(row["tix"]),
|
||||||
|
),
|
||||||
|
foil=row["isFoil"] if row["isFoil"] is not None else False,
|
||||||
|
collection=row["collection"] or "Default",
|
||||||
)
|
)
|
||||||
for row in rows
|
for row in rows
|
||||||
]
|
]
|
||||||
|
@ -300,12 +304,13 @@ async def store_set(db: psycopg.Cursor, set_code: str, name: str) -> None:
|
||||||
async def store_copy(db: psycopg.Cursor, copy: tutor.models.CardCopy) -> None:
|
async def store_copy(db: psycopg.Cursor, copy: tutor.models.CardCopy) -> None:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO copies ("scryfall_id", "isFoil", "condition")
|
INSERT INTO copies ("scryfall_id", "isFoil", "collection", "condition")
|
||||||
VALUES (%(scryfall_id)s, %(foil)s, %(condition)s)
|
VALUES (%(scryfall_id)s, %(foil)s, %(collection)s, %(condition)s)
|
||||||
""",
|
""",
|
||||||
{
|
{
|
||||||
"scryfall_id": str(copy.card.scryfall_id),
|
"scryfall_id": str(copy.card.scryfall_id),
|
||||||
"foil": copy.foil,
|
"foil": copy.foil,
|
||||||
|
"collection": copy.collection,
|
||||||
"condition": copy.condition,
|
"condition": copy.condition,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -90,4 +90,5 @@ class CardCopy:
|
||||||
card: Card
|
card: Card
|
||||||
foil: bool
|
foil: bool
|
||||||
language: str = "English"
|
language: str = "English"
|
||||||
|
collection: str = "Default"
|
||||||
condition: typing.Optional[str] = None
|
condition: typing.Optional[str] = None
|
||||||
|
|
|
@ -64,7 +64,7 @@ class SearchHandler(tornado.web.RequestHandler):
|
||||||
limit = int(self.get_argument("limit", 10))
|
limit = int(self.get_argument("limit", 10))
|
||||||
sort_by = self.get_argument("sort_by", "rarity")
|
sort_by = self.get_argument("sort_by", "rarity")
|
||||||
search = tutor.search.search.parse(query)
|
search = tutor.search.search.parse(query)
|
||||||
cards = await tutor.database.advanced_search(
|
copies = await tutor.database.advanced_search(
|
||||||
cursor,
|
cursor,
|
||||||
search,
|
search,
|
||||||
limit=limit + 1,
|
limit=limit + 1,
|
||||||
|
@ -74,7 +74,7 @@ class SearchHandler(tornado.web.RequestHandler):
|
||||||
if in_collection
|
if in_collection
|
||||||
else None,
|
else None,
|
||||||
)
|
)
|
||||||
has_more = cards and len(cards) > limit
|
has_more = copies and len(copies) > limit
|
||||||
self.set_header("Content-Type", "application/json")
|
self.set_header("Content-Type", "application/json")
|
||||||
self.set_header("Access-Control-Allow-Origin", "*")
|
self.set_header("Access-Control-Allow-Origin", "*")
|
||||||
links = {}
|
links = {}
|
||||||
|
@ -92,24 +92,26 @@ class SearchHandler(tornado.web.RequestHandler):
|
||||||
json.dumps(
|
json.dumps(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"scryfall_id": str(card.scryfall_id),
|
"scryfall_id": str(copy.card.scryfall_id),
|
||||||
"name": card.name,
|
"name": copy.card.name,
|
||||||
"set_code": card.set_code,
|
"set_code": copy.card.set_code,
|
||||||
"collector_number": card.collector_number,
|
"collector_number": copy.card.collector_number,
|
||||||
"rarity": str(card.rarity),
|
"rarity": str(copy.card.rarity),
|
||||||
"color_identity": tutor.models.Color.to_string(
|
"color_identity": tutor.models.Color.to_string(
|
||||||
card.color_identity
|
copy.card.color_identity
|
||||||
),
|
),
|
||||||
"oracle_text": card.oracle_text,
|
"oracle_text": copy.card.oracle_text,
|
||||||
"prices": {
|
"prices": {
|
||||||
"usd": price(card.price_usd),
|
"usd": price(copy.card.price_usd),
|
||||||
"usd_foil": price(card.price_usd_foil),
|
"usd_foil": price(copy.card.price_usd_foil),
|
||||||
"eur": price(card.price_eur),
|
"eur": price(copy.card.price_eur),
|
||||||
"eur_foil": price(card.price_eur_foil),
|
"eur_foil": price(copy.card.price_eur_foil),
|
||||||
"tix": price(card.price_tix),
|
"tix": price(copy.card.price_tix),
|
||||||
}
|
},
|
||||||
|
"foil": copy.foil,
|
||||||
|
"collection": copy.collection,
|
||||||
}
|
}
|
||||||
for card in cards[:limit]
|
for copy in copies[:limit]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -326,6 +326,9 @@ colors =
|
||||||
white =
|
white =
|
||||||
E.rgb255 255 255 255
|
E.rgb255 255 255 255
|
||||||
|
|
||||||
|
offwhite =
|
||||||
|
E.rgb255 200 200 200
|
||||||
|
|
||||||
mythic =
|
mythic =
|
||||||
E.rgb255 205 55 0
|
E.rgb255 205 55 0
|
||||||
|
|
||||||
|
@ -345,7 +348,9 @@ colors =
|
||||||
, sidebar = lighterGrey
|
, sidebar = lighterGrey
|
||||||
, selected = darkGrey
|
, selected = darkGrey
|
||||||
, hover = grey
|
, hover = grey
|
||||||
, text = white
|
, title = white
|
||||||
|
, subtitle = offwhite
|
||||||
|
, text = offwhite
|
||||||
, mythic = mythic
|
, mythic = mythic
|
||||||
, rare = rare
|
, rare = rare
|
||||||
, uncommon = uncommon
|
, uncommon = uncommon
|
||||||
|
@ -458,6 +463,7 @@ viewCardBrowser model =
|
||||||
, E.padding 2
|
, E.padding 2
|
||||||
, Font.family [ Font.typeface "sans" ]
|
, Font.family [ Font.typeface "sans" ]
|
||||||
, Font.size 10
|
, Font.size 10
|
||||||
|
, Font.color colors.title
|
||||||
]
|
]
|
||||||
<|
|
<|
|
||||||
E.text text
|
E.text text
|
||||||
|
@ -514,7 +520,7 @@ viewCardBrowser model =
|
||||||
E.el [ E.centerX ]
|
E.el [ E.centerX ]
|
||||||
(viewCard { width = 192, height = 272 } card)
|
(viewCard { width = 192, height = 272 } card)
|
||||||
:: (E.row [ E.spacing 5, E.centerX ] <| List.map priceBadge (prices card))
|
:: (E.row [ E.spacing 5, E.centerX ] <| List.map priceBadge (prices card))
|
||||||
:: E.paragraph [ Font.heavy, Font.size 24, Font.center ] [ E.text card.name ]
|
:: E.paragraph [ Font.heavy, Font.size 24, Font.center, Font.color colors.title ] [ E.text card.name ]
|
||||||
:: List.map (\text -> E.paragraph [ Font.size 16 ] [ E.text text ])
|
:: List.map (\text -> E.paragraph [ Font.size 16 ] [ E.text text ])
|
||||||
(String.lines card.oracleText)
|
(String.lines card.oracleText)
|
||||||
|
|
||||||
|
@ -551,7 +557,10 @@ viewCardBrowser model =
|
||||||
]
|
]
|
||||||
, description = cardModel.name
|
, description = cardModel.name
|
||||||
}
|
}
|
||||||
, E.el [ E.centerY, E.height E.fill, E.width E.fill, E.clipX ] <| E.text cardModel.name
|
, E.column [ E.centerY, E.height E.fill, E.width E.fill, E.clipX ]
|
||||||
|
[ E.el [ Font.color colors.title ] <| E.text cardModel.name
|
||||||
|
, E.el [ Font.size 16, Font.italic, Font.color colors.subtitle ] <| E.text cardModel.collection
|
||||||
|
]
|
||||||
, E.column [ E.alignRight, E.height E.fill ] <|
|
, E.column [ E.alignRight, E.height E.fill ] <|
|
||||||
setBadge cardModel
|
setBadge cardModel
|
||||||
:: List.map priceBadge (prices cardModel)
|
:: List.map priceBadge (prices cardModel)
|
||||||
|
|
|
@ -20,8 +20,11 @@ type alias Card =
|
||||||
, rarity : String
|
, rarity : String
|
||||||
, oracleText : String
|
, oracleText : String
|
||||||
, prices : Prices
|
, prices : Prices
|
||||||
|
, collection : String
|
||||||
|
, foil : Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
decode : Json.Decode.Decoder Card
|
decode : Json.Decode.Decoder Card
|
||||||
decode =
|
decode =
|
||||||
Json.Decode.succeed Card
|
Json.Decode.succeed Card
|
||||||
|
@ -34,6 +37,8 @@ decode =
|
||||||
|> Json.Decode.map (Maybe.withDefault "")
|
|> Json.Decode.map (Maybe.withDefault "")
|
||||||
)
|
)
|
||||||
|> JDP.required "prices" decodePrices
|
|> JDP.required "prices" decodePrices
|
||||||
|
|> JDP.required "collection" Json.Decode.string
|
||||||
|
|> JDP.required "foil" Json.Decode.bool
|
||||||
|
|
||||||
|
|
||||||
decodePrices : Json.Decode.Decoder Prices
|
decodePrices : Json.Decode.Decoder Prices
|
||||||
|
|
Loading…
Reference in a new issue