Created
March 8, 2023 15:06
-
-
Save eramax/2a651152cbbb4c73d9b9e63e869abea9 to your computer and use it in GitHub Desktop.
Remove telegram groups
This file contains hidden or 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
# Remove telegram groups | |
# python3 -m pip install --upgrade telethon | |
from telethon import TelegramClient, sync | |
# get an Id from https://my.telegram.org/apps | |
api_id = 111111111111 | |
api_hash = 'xxxxxxxxxxxxx' | |
# List all the group names you want to keep, the script will delete other groups. | |
excluded_groups = ['gp1','gp2'] | |
class TelegramAPIs(object): | |
def init_client(self, session_name, api_id, api_hash): | |
self.client = TelegramClient(session_name, api_id, api_hash) | |
self.client.start() | |
def close_client(self): | |
if self.client.is_connected(): | |
self.client.disconnect() | |
def clean(self): | |
for dialog in self.client.get_dialogs(): | |
if hasattr(dialog.entity, "title") and dialog.entity.title not in excluded_groups: | |
print('----- deleting ', dialog.entity.title) | |
self.client.delete_dialog(dialog.entity) | |
ta = TelegramAPIs() | |
ta.init_client(session_name='session_name', api_id=api_id, api_hash=api_hash) | |
ta.clean() | |
ta.close_client() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.youtube.com/watch?v=bAbkVyaEzag