Updated dump script.
This commit is contained in:
		
							parent
							
								
									70db15bf27
								
							
						
					
					
						commit
						3960390ec4
					
				| @ -12,20 +12,18 @@ async def fix_message(message): | |||||||
|     ) |     ) | ||||||
|     user = await app.services.user.get(uid=message['user_uid']) |     user = await app.services.user.get(uid=message['user_uid']) | ||||||
|     message['user'] = user and user['username'] or None |     message['user'] = user and user['username'] or None | ||||||
|     return message |     return (message['user'] or '') + ': ' + (message['text'] or '') | ||||||
| 
 | 
 | ||||||
| async def dump_public_channels(): | async def dump_public_channels(): | ||||||
|     result = {'channels':{}} |     result = [] | ||||||
|     for channel in app.db['channel'].find(is_private=False,is_listed=True,tag='public'): |     for channel in app.db['channel'].find(is_private=False,is_listed=True,tag='public'): | ||||||
|         print(f"Dumping channel: {channel['label']}.") |         print(f"Dumping channel: {channel['label']}.") | ||||||
|         result['channels'][channel['label']] = dict(channel) |         result += [await fix_message(record) for record in app.db['channel_message'].find(channel_uid=channel['uid'],order_by='created_at')] | ||||||
|         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')] |  | ||||||
|         print("Dump succesfull!") |         print("Dump succesfull!") | ||||||
|     print("Converting to json.") |     print("Converting to json.") | ||||||
|     data = json.dumps(result, indent=4,default=str) |  | ||||||
|     print("Converting succesful, now writing to dump.json") |     print("Converting succesful, now writing to dump.json") | ||||||
|     with open("dump.json","w") as f: |     with open("dump.txt","w") as f: | ||||||
|         f.write(data) |         f.write('\n\n'.join(result)) | ||||||
|     print("Dump written to dump.json") |     print("Dump written to dump.json") | ||||||
|      |      | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user