Update.
This commit is contained in:
		
							parent
							
								
									cb310967cd
								
							
						
					
					
						commit
						149659064d
					
				| @ -13,7 +13,49 @@ from snek.app import Application | |||||||
| def cli(): | def cli(): | ||||||
|     pass |     pass | ||||||
| 
 | 
 | ||||||
|  | @cli.command() | ||||||
|  | def export(): | ||||||
| 
 | 
 | ||||||
|  |     app = Application(db_path="sqlite:///snek.db") | ||||||
|  | 
 | ||||||
|  |     async def fix_message(message): | ||||||
|  |         message = { | ||||||
|  |             "uid": message["uid"], | ||||||
|  |             "user_uid": message["user_uid"], | ||||||
|  |             "text": message["message"], | ||||||
|  |             "sent": message["created_at"], | ||||||
|  |         } | ||||||
|  |         user = await app.services.user.get(uid=message["user_uid"]) | ||||||
|  |         message["user"] = user and user["username"] or None | ||||||
|  |         return (message["user"] or "") + ": " + (message["text"] or "") | ||||||
|  |     async def run(): | ||||||
|  | 
 | ||||||
|  |         result = [] | ||||||
|  |         for channel in app.db["channel"].find( | ||||||
|  |             is_private=False, is_listed=True, tag="public" | ||||||
|  |         ): | ||||||
|  |             print(f"Dumping channel: {channel['label']}.") | ||||||
|  |             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.") | ||||||
|  |         print("Converting succesful, now writing to dump.txt") | ||||||
|  |         with open("dump.txt", "w") as f: | ||||||
|  |             f.write("\n\n".join(result)) | ||||||
|  |         print("Dump written to dump.json") | ||||||
|  |     asyncio.run(run()) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @cli.command() | ||||||
|  | def statistics(): | ||||||
|  |     async def run(): | ||||||
|  |         app = Application(db_path="sqlite:///snek.db") | ||||||
|  |         app.services.statistics.database() | ||||||
|  |     asyncio.run(run()) | ||||||
| 
 | 
 | ||||||
| @cli.command() | @cli.command() | ||||||
| def maintenance(): | def maintenance(): | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user