Updated dump script.

This commit is contained in:
retoor 2025-03-18 21:06:28 +00:00
parent 70db15bf27
commit 3960390ec4

View File

@ -12,20 +12,18 @@ async def fix_message(message):
)
user = await app.services.user.get(uid=message['user_uid'])
message['user'] = user and user['username'] or None
return message
return (message['user'] or '') + ': ' + (message['text'] or '')
async def dump_public_channels():
result = {'channels':{}}
result = []
for channel in app.db['channel'].find(is_private=False,is_listed=True,tag='public'):
print(f"Dumping channel: {channel['label']}.")
result['channels'][channel['label']] = dict(channel)
result['channels'][channel['label']]['messages'] = [await fix_message(record) for record in app.db['channel_message'].find(channel_uid=channel['uid'],order_by='created_at')]
result += [await fix_message(record) for record in app.db['channel_message'].find(channel_uid=channel['uid'],order_by='created_at')]
print("Dump succesfull!")
print("Converting to json.")
data = json.dumps(result, indent=4,default=str)
print("Converting succesful, now writing to dump.json")
with open("dump.json","w") as f:
f.write(data)
with open("dump.txt","w") as f:
f.write('\n\n'.join(result))
print("Dump written to dump.json")