Skip to content

Instantly share code, notes, and snippets.

@sijis
Created May 27, 2015 17:09
Show Gist options
  • Save sijis/7e3f43949d12fde56a68 to your computer and use it in GitHub Desktop.
Save sijis/7e3f43949d12fde56a68 to your computer and use it in GitHub Desktop.
exporting plugin data
import shelve
import os
import json
def date_handler(obj):
return obj.isoformat() if hasattr(obj, 'isoformat') else obj
for filename in os.listdir('.'):
if '.db' in filename:
dump_filename = '{}.{}'.format(filename.split('.')[0], 'json')
shelve_obj = shelve.open(filename)
if dict(shelve_obj) == {}:
print '{} - skipping'.format(filename)
continue
with open(dump_filename, 'w') as f:
data = str(shelve_obj)
print '{} -> {} - dumping'.format(filename, dump_filename)
print '{}: {}'.format(type(data), data)
json.dump(obj=data, fp=f, default=None)
f.close()
import shelve
import os
import ast
import json
for filename in os.listdir('.'):
if '.json' in filename:
dump_filename = '{}.{}'.format(filename.split('.')[0], 'db2')
if not os.path.getsize(filename) > 0:
print('{} - skippped'.format(filename))
continue
with open(filename, 'rb') as f:
print('{} - importing'.format(filename))
#data = json.load(f)
print(f.read())
data = json.loads(f.read())
print(data)
data_ = ast.literal_eval(data)
#d = shelve.open(dump_filename, writeback=True)
#d.update(data_)
#d.sync()
#d.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment