Skip to content

Instantly share code, notes, and snippets.

@obihann
Forked from jewel-andraia/README.md
Last active August 13, 2023 21:55
Show Gist options
  • Save obihann/9685602 to your computer and use it in GitHub Desktop.
Save obihann/9685602 to your computer and use it in GitHub Desktop.
Two Python scripts to help RES (Reddit Enhancement Suite) users manage their backups and convert between platforms.
#!/usr/bin/python
import json
import codecs
import sqlite3
con = sqlite3.connect('res.db')
cur = con.cursor()
db = cur.execute('SELECT key, CAST(value as TEXT) FROM ItemTable').fetchall()
with codecs.open('store.json', 'w', 'utf-8') as f:
dump = json.dumps(dict(db))
f.write(dump)
#!/usr/bin/python
import json
import codecs
import sqlite3
con = sqlite3.connect('res.db')
cur = con.cursor()
cur.execute('CREATE TABLE ItemTable (key TEXT UNIQUE ON CONFLICT REPLACE, value BLOB NOT NULL ON CONFLICT FAIL)')
with codecs.open('store.json', 'rU', 'utf-8') as data_file:
data = json.load(data_file)
for (key, value) in data.items():
cur.execute('INSERT INTO ItemTable values (?,?)', (key, value))
con.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment