Skip to content

Instantly share code, notes, and snippets.

@joseluis
Forked from obihann/README.md
Created November 14, 2017 12:54
Show Gist options
  • Save joseluis/b61f4d9ad702bb160109791d67c5fbc2 to your computer and use it in GitHub Desktop.
Save joseluis/b61f4d9ad702bb160109791d67c5fbc2 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