From 559d07b55d8dd5252337de211259a5b573407839 Mon Sep 17 00:00:00 2001 From: Mark Cheese <35660089+omfgitsmark@users.noreply.github.com> Date: Mon, 4 Nov 2019 18:57:05 -0500 Subject: [PATCH] Price value validation added. (#35) --- mtgsqlive/json2sql.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/mtgsqlive/json2sql.py b/mtgsqlive/json2sql.py index a40f17c..ea0bc6b 100644 --- a/mtgsqlive/json2sql.py +++ b/mtgsqlive/json2sql.py @@ -179,7 +179,6 @@ def build_sql_schema(output_file: Dict) -> None: "variations TEXT,", "watermark TEXT", ");", - # "CREATE UNIQUE INDEX 'cards_uuid' ON cards(uuid);" "", "", ], @@ -481,15 +480,15 @@ def handle_price_rows( for price_type in card_data["prices"]: if card_data["prices"][price_type] is not None: for date, price in card_data["prices"][price_type].items(): - prices.append( - { - "uuid": card_uuid, - "type": price_type, - "price": price, - "date": date, - } - ) - + if price: + prices.append( + { + "uuid": card_uuid, + "type": price_type, + "price": price, + "date": date, + } + ) return prices @@ -628,8 +627,12 @@ def sql_dict_insert(data: Dict[str, Any], table: str, output_file: Dict) -> None query = query.format(**data) output_file["handle"].write(query) else: - cursor = output_file["handle"].cursor() - columns = ", ".join(data.keys()) - placeholders = ":" + ", :".join(data.keys()) - query = f"INSERT INTO {table} ({columns}) VALUES ({placeholders})" - cursor.execute(query, data) + try: + cursor = output_file["handle"].cursor() + columns = ", ".join(data.keys()) + placeholders = ":" + ", :".join(data.keys()) + query = f"INSERT INTO {table} ({columns}) VALUES ({placeholders})" + cursor.execute(query, data) + except: + datastr = str(data) + LOGGER.warning(f"Failed to insert row in {table} with values {datastr}")