Last active
December 31, 2015 04:29
-
-
Save scragg0x/7934931 to your computer and use it in GitHub Desktop.
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 os | |
import json | |
import time | |
sql_data_file = 'app_data.sqlite' | |
dirname = os.path.dirname(os.path.realpath(__file__)) | |
ts = int(time.time()) | |
try: | |
os.makedirs('%s%sdata%s%s' % (dirname, os.sep, os.sep, ts)) | |
except OSError: | |
pass | |
conn = sqlite3.connect(sql_data_file) | |
c = conn.cursor() | |
c.execute("SELECT * FROM sqlite_master WHERE type='table'") | |
tables = c.fetchall() | |
for table in tables: | |
print "Processing", table[1] | |
c.execute("SELECT * FROM %s" % table[1]) | |
d = dict(names=list(map(lambda x: x[0], c.description)), | |
data=c.fetchall()) | |
f = open("%s%sdata%s%s%s%s.json" % (dirname, os.sep, os.sep, ts, os.sep, table[1]), 'w') | |
f.write(json.dumps(d)) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment