N
N
new20leon2020-10-24 14:25:37
Python
new20leon, 2020-10-24 14:25:37

How to parse group/channel contacts from telegram using your account via python?

Telegram is a complete example of how to collect all users from a group / channel on behalf of your account. Collect all (if any) accounts with photos (not empty), nicknames (if any), Description (about yourself), when the person was (if the account was a long time ago, then do not take into account). Paste into excel file.

I can't start writing code to work. Where to find complete examples and how to write?

import configparser
import json

from telethon.sync import TelegramClient
from telethon import connection

# для корректного переноса времени сообщений в json
from datetime import date, datetime

# классы для работы с каналами
from telethon.tl.functions.channels import GetParticipantsRequest
from telethon.tl.types import ChannelParticipantsSearch

# класс для работы с сообщениями
from telethon.tl.functions.messages import GetHistoryRequest





# Считываем учетные данные
config = configparser.ConfigParser()
config.read("config.ini")

# Присваиваем значения внутренним переменным
api_id   = config['Telegram']['api_id']
api_hash = config['Telegram']['api_hash']
username = config['Telegram']['username']

#kontakt_apppp
#kontaktapppp

client = TelegramClient(username, api_id, api_hash)



#proxy = (proxy_server, proxy_port, proxy_key)
#proxy = ('144.76.214.154', '1080', 'secret')


client = TelegramClient(username, api_id, api_hash,
    connection=None,
    proxy=None)



#client = TelegramClient(username, api_id, api_hash,
#    connection=connection.ConnectionTcpMTProxyRandomizedIntermediate,
#    proxy=None)

client.start()


line 49, in client = TelegramClient(username, api_id, api_hash, File "C:\Python38\lib\site-packages\telethon\client\telegrambaseclient.py", line 269, in init session.set_dc( File "C:\ Python38\lib\site-packages\telethon\sessions\sqlite.py", line 163, in set_dc self._update_session_table() File "C:\Python38\lib\site-packages\telethon\sessions\sqlite.py", line 189, in _update_session_table c.execute('delete from sessions') sqlite3.OperationalError: database is locked

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2020-10-25
@shurshur

Here, the TelegramClient is created twice in the code, one of them locks the session file, the second one then crashes due to the fact that it was locked by the first one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question