-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_recent_changes.py
More file actions
76 lines (56 loc) · 1.8 KB
/
print_recent_changes.py
File metadata and controls
76 lines (56 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/python3
import json
import sqlite3
import importlib
import os
import datetime
import config
import sqlite_helper as sqlh
db = sqlh.Sqlite_helper(config.db_filepath, dry_run=True)
dbcur = db.con.cursor()
# i dont trust python data structures?
# i dont know if all ids are unique lol
tmp_con = sqlite3.connect(":memory:")
tcur = tmp_con.cursor()
tcur.execute("CREATE TABLE entries(id, name, slug, parent, time)")
# detect mod insertions / deletions
# use time field of api table
tablecur = db.con.cursor()
tablecur.execute("SELECT COUNT(*) FROM api")
entry_count = tablecur.fetchone()[0]
tablecur.execute("SELECT * FROM api")
print(f"Processing {entry_count} records")
counter = 0
for api_raw in tablecur:
json_data = json.loads(api_raw[2])
time_point = api_raw[1]
if counter % 5 == 0:
print(f"\r{counter}/{entry_count}", end='', flush=True)
counter += 1
if not json_data and not 'data' in json_data:
continue
for entry in json_data['data']:
if isinstance(entry, str) or not 'id' in entry:
continue
id = entry['id']
name = id
slug = id
parent = id
if 'displayName' in entry:
name = entry['displayName']
if 'name' in entry:
name = entry['name']
if 'slug' in entry:
slug = entry['slug']
if 'gameId' in entry:
parent = entry['gameId']
if 'primaryCategoryId' in entry:
parent = entry['primaryCategoryId']
if 'modId' in entry:
parent = entry['modId']
tcur.execute("INSERT OR REPLACE INTO entries(id, name, slug, parent, time) VALUES(?,?,?,?,?)",
(id, name, slug, parent, time_point))
# print data
tcur.execute("SELECT * FROM entries ORDER BY time")
for entry in tcur:
print(entry)