Created
July 7, 2021 13:52
-
-
Save Yepoleb/c357a5a4e9ef7f3f8fdef23432b6994a to your computer and use it in GitHub Desktop.
Query GOG DB index for removed bonus content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
import datetime | |
import json | |
import csv | |
import sys | |
INDEX_PATH = "gogdb_index.sqlite3" | |
START_DATE = "2021-01-12" | |
conn = sqlite3.connect(INDEX_PATH) | |
cur = conn.cursor() | |
date_timestamp = datetime.datetime.fromisoformat(START_DATE).timestamp() | |
cur.execute( | |
"SELECT product_id, product_title, serialized_record FROM changelog " \ | |
"WHERE action = 'del' AND dl_type = 'bonus' AND timestamp >= ?" \ | |
"ORDER BY product_title ASC, timestamp ASC", (date_timestamp,) | |
) | |
csv_out = csv.writer(sys.stdout) | |
for row in cur: | |
product_id, product_title, serialized_record = row | |
record = json.loads(serialized_record) | |
bonus_item = record["download_record"]["dl_old_bonus"] | |
bonus_id = bonus_item["id"] | |
bonus_name = bonus_item["name"] | |
bonus_count = bonus_item["count"] | |
bonus_size = bonus_item["total_size"] | |
csv_out.writerow([product_id, product_title, bonus_id, bonus_name, bonus_count, bonus_size]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment