Skip to content

Instantly share code, notes, and snippets.

View amiryousefi's full-sized avatar

Amir Yousefi amiryousefi

View GitHub Profile
@amiryousefi
amiryousefi / buffer-pablo-like-social-media-graphic-designer.markdown
Created July 5, 2019 13:43
Buffer Pablo like social media graphic designer
@amiryousefi
amiryousefi / a-telegram-data-analysis-tool.markdown
Last active August 10, 2019 13:33
A gist to explain how to get Telegram channels members

Telegram Analysis tools

user_input_channel = input("enter entity(telegram URL or entity id):")
if user_input_channel.isdigit():
entity = PeerChannel(int(user_input_channel))
else:
entity = user_input_channel
my_channel = client.get_entity(entity)
offset = 0
limit = 100
all_participants = []
while True:
participants = client(GetParticipantsRequest(
my_channel, ChannelParticipantsSearch(''), offset, limit,
hash=0
))
all_user_details = []
for participant in all_participants:
all_user_details.append(
{"id": participant.id, "first_name": participant.first_name, "last_name": participant.last_name,
"user": participant.username, "phone": participant.phone, "is_bot": participant.bot})
with open('user_data.json', 'w') as outfile:
json.dump(all_user_details, outfile)
offset_id = 0
limit = 100
all_messages = []
total_messages = 0
total_count_limit = 0
while True:
print("Current Offset ID is:", offset_id, "; Total Messages:", total_messages)
history = client(GetHistoryRequest(
import configparser
import json
from telethon import TelegramClient
from telethon.errors import SessionPasswordNeededError
# Reading Configs
config = configparser.ConfigParser()
config.read("config.ini")
# Setting configuration values
api_id = config['Telegram']['api_id']
api_hash = config['Telegram']['api_hash']
api_hash = str(api_hash)
@amiryousefi
amiryousefi / config.ini
Created August 14, 2019 09:17
Telegram credentials
[Telegram]
# no need for quotes
# you can get telegram development credentials in telegram API Development Tools
api_id = Telegram-API-ID
api_hash = Telegram-API-Hash
# use full phone number including + and country code
phone = Your-Telegram-Phone-Number
username = Your-Telegram-Username
# Create the client and connect
client = TelegramClient(username, api_id, api_hash)
client.start()
print("Client Created")
# Ensure you're authorized
if not client.is_user_authorized():
client.send_code_request(phone)
try:
client.sign_in(phone, input('Enter the code: '))
except SessionPasswordNeededError: