Last active
March 5, 2023 09:18
-
-
Save dolohow/9f02960428020d2ec1ba33053ee61659 to your computer and use it in GitHub Desktop.
Backup and delete old messages on telegram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import pymongo | |
import json | |
import asyncio | |
from pyrogram import Client | |
client = pymongo.MongoClient("localhost", 27017) | |
db = client.telegram | |
# Configure here | |
api_id = | |
api_hash = '' | |
chat_id = '-' | |
app = Client("my_account", api_id, api_hash) | |
async def main(): | |
async with app: | |
async for message in app.get_chat_history(chat_id): | |
if message.date.year < 2023 and message.text and not message.media: | |
db.lapsy.insert_one(json.loads(str(message))) | |
asyncio.create_task(message.delete()) | |
app.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment