from telethon import TelegramClient, sync, events
import config
def main_parsing(bot, message):
api_id = config.api_id
api_hash = config.api_hash
phone = config.number
client = TelegramClient(phone, api_id, api_hash)
@client.on(events.NewMessage(chats=(config.link)))
async def normal_handler(event):
# print(event.message)
user_mess = event.message.to_dict()['message']
s_user_id = event.message.to_dict()['from_id']
user_id = str(s_user_id['user_id'])
mess_date = event.message.to_dict()['date']
f.write(mess_date.strftime("%d-%m-%Y %H:%M") + "\n")
f.write(user_id + "\n")
f.write(user_mess + "\n\n")
await bot.send_message(message.from_user.id, f'{mess_date.strftime("%d-%m-%Y %H:%M")}\n{user_id}\n{user_mess}')
f.flush()
client.start()
group = config.link
participants = client.get_participants(group)
users = {}
for partic in client.iter_participants(group):
lastname = ""
if partic.last_name:
lastname = partic.last_name
users[partic.id] = partic.first_name + " " + lastname
f = open('messages_from_chat', 'a')
client.run_until_disconnected()
f.close()