This commit is contained in:
mrbesen 2018-10-14 00:09:51 +02:00
commit 83fa3f7bfe
4 changed files with 154 additions and 0 deletions

69
.gitignore vendored Normal file
View File

@ -0,0 +1,69 @@
#private files:
src/config.ini
src/*.session
TODO
.idea/
venv/
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/

8
LICENSE Normal file
View File

@ -0,0 +1,8 @@
MIT License
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# TelegramDelete
Telegramclient, welcher Löschen vieler Nachrichten beschleunigt.

74
src/AutoDelete.py Executable file
View File

@ -0,0 +1,74 @@
#!/usr/bin/env python3
from telethon import TelegramClient
import configparser
from datetime import datetime
import os
dialogs = [] # list of known chats
me = None # the own entity
client = None
def printDialog(id , d):
# print (d.id, " ", d.name," ", d.pinned)
print('{0:2d} | {1:14d} | {2:30} | {3:1}'.format(id, d.id,d.name,d.pinned))
# ==================================
# MAIN program
# read config
try:
config = configparser.ConfigParser()
config.read('config.ini')
api_id = int(config.get('Main', 'api_id'))
api_hash = config.get('Main', 'api_hash')
workers = int(config.get('Main', 'workers'))
session_name = config.get('Main', 'user')
#print('apiid:', api_id, 'hash:', api_hash, 'worker', workers, 'sessionname', session_name)
except (configparser.NoSectionError, configparser.NoOptionError, ValueError):
print('invalid config.ini')
exit(3)
# create connection
client = TelegramClient(session_name, api_id, api_hash)
client.start()
print('client started')
me = client.get_me()
print(me)
# get dialogs
dialogs = client.get_dialogs(limit=100)
print(len(dialogs), ' Chats loaded.')
id = 0
#table header
print ('ID | Internal ID | Username | pinned\n———+————————————————+————————————————————————————————+———————')
#content
for d in dialogs:
printDialog(id,d)
id = id+1
get = int(input("Please Enter Chat ID: "))
if get < 0 or get >= id:
print ("Unknown Chat ID!")
exit(1)
selectedDialog = dialogs[get]
print ("selected: ", selectedDialog.name, 'retriving chat!')
chat = client.get_messages(selectedDialog, limit=2000000)
print("retrived ", len(chat), 'Messages.\nEnter a Date in the format: yyyy-mm-dd after wich all msgs should be deleted.')
datein = input("Date:")
date = datetime.strptime(datein, '%Y-%m-%d').replace(tzinfo=None)
print('Deleting...')
messagecount = 0
for msg in chat:
if msg != None:
if msg.date.replace(tzinfo=None) < date:
messagecount = messagecount+1
msg.delete()
print(messagecount, 'Messages deleted.')
print('End.')