From bc24cea919f962afe1077a5782ab24535d69f4e2 Mon Sep 17 00:00:00 2001 From: Jakob Cornell Date: Sat, 9 Oct 2021 15:44:40 -0500 Subject: [PATCH] Handle absence of all group and torrent data fields --- python/scripts/ingest_ptp_json.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/python/scripts/ingest_ptp_json.py b/python/scripts/ingest_ptp_json.py index 793f614..5077113 100644 --- a/python/scripts/ingest_ptp_json.py +++ b/python/scripts/ingest_ptp_json.py @@ -21,6 +21,7 @@ for p in paths: def ingest(doc, db_cursor): for group in doc["Movies"]: + group_id = group["GroupId"] stmt = ( "insert into ptp.torrent_group (id, title, year, imdb_id)" + " values (%s, %s, %s, %s)" @@ -29,7 +30,7 @@ def ingest(doc, db_cursor): ) db_cursor.execute( stmt, - (group["GroupId"], group["Title"], group["Year"], group.get("ImdbId")) + (group_id, group.get("Title"), group.get("Year"), group.get("ImdbId")) ) group_cols = "(group_id, torrentid, quality, source, container, codec, resolution, seeders, leechers, snatched)" @@ -40,13 +41,18 @@ def ingest(doc, db_cursor): + ";" ) for torrent in group["Torrents"]: + id_ = torrent["Id"] + quality = torrent.get("Quality") + source = torrent.get("Source") + container = torrent.get("Container") + codec = torrent.get("Codec") + resolution = torrent.get("Resolution") + seeders = int(torrent["Seeders"]) if "Seeders" in torrent else None + leechers = int(torrent["Leechers"]) if "Leechers" in torrent else None + snatched = int(torrent["Snatched"]) if "Snatched" in torrent else None db_cursor.execute( stmt, - ( - group["GroupId"], torrent["Id"], torrent["Quality"], torrent["Source"], torrent["Container"], - torrent["Codec"], torrent["Resolution"], int(torrent["Seeders"]), int(torrent["Leechers"]), - int(torrent["Snatched"]), - ) + (group_id, id_, quality, source, container, codec, resolution, seeders, leechers, snatched), ) -- 2.30.2