Files
politics-mark/grab_samples.py
Anatoly 00b1287ef3
All checks were successful
continuous-integration/drone/push Build is passing
Catch none type sentences
2022-04-03 10:55:20 +03:00

43 lines
815 B
Python

import os
from dotenv import load_dotenv
from telethon.sync import TelegramClient
load_dotenv()
api_id = os.getenv('API_ID')
api_hash = os.getenv('API_HASH')
chats = [
'tg1337const',
'cyberboec'
]
def cleanup(msg):
unwanted_strings = [
'[1337const | подписаться](https://t.me/tg1337const)',
'[1337const | Подписаться](https://t.me/tg1337const)',
'**',
'__'
]
try:
for unwanted in unwanted_strings:
msg = msg.replace(unwanted, '')
return msg
except:
return msg
with TelegramClient('bot', api_id, api_hash) as client:
f = open("data/data.txt", "w")
for chat in chats:
print(f'Collecting {chat}')
for message in client.iter_messages(chat):
try:
f.write(cleanup(message.text))
except:
pass
f.close()