-
Notifications
You must be signed in to change notification settings - Fork 415
/
unpickle.py
41 lines (34 loc) · 1.31 KB
/
unpickle.py
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
import os
os.environ["GRAMPS_RESOURCES"] = "/home/dsblank/gramps/gramps"
from gramps.gen.db.utils import open_database
import pickle
import json
db = open_database("Example")
###########################################################################
try:
db.dbapi.execute("ALTER TABLE family ADD COLUMN unblob TEXT;")
db.dbapi.commit()
except Exception:
pass
db.dbapi.execute("SELECT handle from family;")
handles = [x[0] for x in db.dbapi.fetchall()]
for handle in handles:
db.dbapi.execute("SELECT blob_data FROM family WHERE handle = ? limit 1;", [handle])
row = db.dbapi.fetchone()
unblob = json.dumps(pickle.loads(row[0]))
db.dbapi.execute("UPDATE family SET unblob = ? where handle = ?;", [unblob, handle])
db.dbapi.commit()
###########################################################################
try:
db.dbapi.execute("ALTER TABLE person ADD COLUMN unblob TEXT;")
except Exception:
pass
db.dbapi.execute("SELECT handle from person;")
handles = [x[0] for x in db.dbapi.fetchall()]
for handle in handles:
db.dbapi.execute("SELECT blob_data FROM person WHERE handle = ? limit 1;", [handle])
row = db.dbapi.fetchone()
unblob = json.dumps(pickle.loads(row[0]))
db.dbapi.execute("UPDATE person SET unblob = ? where handle = ?;", [unblob, handle])
db.dbapi.commit()
db.close()