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)"
)
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)"
+ ";"
)
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),
)