31 lines
693 B
Python
31 lines
693 B
Python
|
import bson
|
||
|
import datetime
|
||
|
import json
|
||
|
import importlib
|
||
|
|
||
|
import DateTimeEncoder from utils
|
||
|
|
||
|
data = {
|
||
|
"content_items": [],
|
||
|
"content_item_categories": [],
|
||
|
"tags": [],
|
||
|
"email_subscriptions": [],
|
||
|
"users": [],
|
||
|
"comments": []
|
||
|
}
|
||
|
|
||
|
def json_tables():
|
||
|
print('creating json files at data/')
|
||
|
|
||
|
for table in data.keys():
|
||
|
lc = []
|
||
|
with open('data/'+table+'.bson', 'rb') as f:
|
||
|
bs = f.read()
|
||
|
base = 0
|
||
|
while base < len(bs):
|
||
|
base, d = bson.decode_document(bs, base)
|
||
|
lc.append(d)
|
||
|
data[table] = lc
|
||
|
open('data/'+table+'.json', 'w').write(json.dumps(lc,cls=DateTimeEncoder))
|
||
|
|