Last active
June 15, 2021 08:06
-
-
Save Mnsrff/9cba7a3231034fac900dd00b692d7c0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from telethon import TelegramClient | |
import pandas as pd | |
import asyncio | |
api_id = '...' | |
api_hash = '...' | |
phone = '+7...' | |
channel_href = 'https://t.me/...' | |
client = TelegramClient('session_name', api_id, api_hash) | |
df = pd.DataFrame() | |
async def start(): | |
client = TelegramClient('session_name', api_id, api_hash) | |
print('1!') | |
client = await client.start() | |
print('2!') | |
dialogs = await client.get_dialogs() | |
print('3!') | |
channels = {d.entity.username: d.entity | |
for d in dialogs | |
if d.is_channel} | |
my_channel = channel_href.split('/')[-1] | |
channel = channels[my_channel] | |
members_telethon_list = await client.get_participants(channel, aggressive=True) | |
username_list = [member.username for member in members_telethon_list] | |
first_name_list = [member.first_name for member in members_telethon_list] | |
last_name_list = [member.last_name for member in members_telethon_list] | |
phone_list = [member.phone for member in members_telethon_list] | |
df['username'] = username_list | |
df['first_name'] = first_name_list | |
df['last_name'] = last_name_list | |
df['phone'] = phone_list | |
client.loop.run_until_complete(start()) | |
def panda(): | |
df.to_csv('subscribers.csv', index=False) | |
print('Done!') | |
panda() | |
print('This is the end.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment