core/migration/bson2json.py

29 lines
664 B
Python
Raw Normal View History

2022-07-07 13:55:13 +00:00
import os
2021-08-20 09:27:19 +00:00
import bson
import json
2021-10-08 09:58:19 +00:00
from migration.utils import DateTimeEncoder
2021-08-20 09:27:19 +00:00
def json_tables():
2022-07-14 12:35:22 +00:00
print('[migration] unpack dump/discours/*.bson to migration/data/*.json')
2021-12-17 18:14:31 +00:00
data = {
"content_items": [],
"content_item_categories": [],
"tags": [],
"email_subscriptions": [],
"users": [],
"comments": []
}
for table in data.keys():
lc = []
2022-07-14 12:35:22 +00:00
with open('dump/discours/'+table+'.bson', 'rb') as f:
2021-12-17 18:14:31 +00:00
bs = f.read()
2022-07-07 13:55:13 +00:00
f.close()
2021-12-17 18:14:31 +00:00
base = 0
while base < len(bs):
base, d = bson.decode_document(bs, base)
lc.append(d)
data[table] = lc
2022-07-14 12:35:22 +00:00
open(os.getcwd() + '/migration/data/'+table+'.json', 'w').write(json.dumps(lc,cls=DateTimeEncoder))
2021-08-20 09:27:19 +00:00