Pa bajarse los grupos de pelegram con un userbot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.0 KiB

import os
import sys
import time
#Gettit with pip bro
from telethon import TelegramClient, events, utils
import json
def get_env(name, message, cast=str):
if name in os.environ:
return os.environ[name]
while True:
value = input(message)
return cast(value)
except ValueError as e:
print(e, file=sys.stderr)
sesion = get_env('TG_SESION', 'Enter your API sesion name: ')
api_id = get_env('TG_API_ID', 'Enter your API ID: ', int)
api_hash = get_env('TG_API_HASH', 'Enter your API hash: ')
# Create and start the client so we can make requests
with TelegramClient(sesion, api_id, api_hash, spawn_read_thread=False)).start() as client:
me = client.get_me()
#TODO: selector de conversaciones si el bot no esta inicializado
chat1 = client.get_entity('')
createNewDump('lonami', chat1)
chat2 = client.get_entity('')
createNewDump('lol', chat2)
chat3 = client.get_entity('')
createNewDump('telegram', chat3)
chats = (chat1, chat2, chat3)
@client.on.message(events.NewMessage(chats=chats, incoming = True))
def handler(events):
def createNewDump(name, entity):
filePath = "./dumps/"+name+"Dump.json"
if !os.path.isfile(filePath):
with open(filePath,"w+") as f:
meta = {'meta':[{
'name': name,
'entity': entity,
'creationDate': strftime("%Y-%m-%d %H:%M:%S", gmtime())
json.dump(meta, f)
def addEntryToDump(name, element):
#TODO Test si existe el dump anterior
filePath = "./dumps/"+name+"Dump.json"
with open(filePath,"w+") as f:
message = {'mensaje':[{
'element': element,
'Date': strftime("%Y-%m-%d %H:%M:%S", gmtime())
json.dump(meta, f)