Last active
August 6, 2019 18:05
-
-
Save Kyborg2011/e4a23b9a2dfd274beb6b991fd06298a6 to your computer and use it in GitHub Desktop.
Revisions
-
Kyborg2011 revised this gist
Aug 6, 2019 . No changes.There are no files selected for viewing
-
Kyborg2011 revised this gist
Aug 6, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -53,7 +53,7 @@ our_channel = 'some_new_crypto_channel_or_group' for user in all_participants: if (index < 50 and i > offset): # Select users considering innitial offset and send no more than 50 invites from one Telegram account (because of some spam protection) print('Success: index - {} Name: {}'.format(i, user.first_name)) try: client(InviteToChannelRequest( -
Kyborg2011 revised this gist
Aug 6, 2019 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -53,7 +53,6 @@ our_channel = 'some_new_crypto_channel_or_group' for user in all_participants: if (index < 50 and i > offset): print('Success: index - {} Name: {}'.format(i, user.first_name)) try: -
Kyborg2011 revised this gist
Aug 6, 2019 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -53,7 +53,8 @@ our_channel = 'some_new_crypto_channel_or_group' for user in all_participants: # Select users considering innitial offset and send no more than 50 invites from one Telegram account (because of some spam protection) if (index < 50 and i > offset): print('Success: index - {} Name: {}'.format(i, user.first_name)) try: client(InviteToChannelRequest( @@ -67,7 +68,8 @@ except: e = sys.exc_info() print(e) # An important line of code! It's a preventing of Flood Error exception (in the most of cases...) time.sleep(20) i += 1 ''' -
Kyborg2011 created this gist
Aug 6, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,85 @@ # For start up make in bash: 'python3 telegram-mailing.py' from telethon import TelegramClient, sync from telethon.tl.functions.channels import GetParticipantsRequest from telethon.tl.types import ChannelParticipantsSearch from telethon.tl.functions.channels import JoinChannelRequest from telethon.tl.functions.channels import InviteToChannelRequest from telethon.errors.rpcerrorlist import PeerFloodError import time import random import sys # These example values won't work. You must get your own api_id and # api_hash from https://my.telegram.org, under API Development. api_id = 700000 # YOUR UNIQUE API ID api_hash = 'qkV0b32ahfyjZqKgrq7z1nC4GuuDbsmop' # YOUR UNIQUE API HASH # For group https://t.me/some_crypto_group (only for examples) channel = 'some_crypto_group' # WORKING ONLY FOR GROUPS!!! NOT CHANNELS!!! (if you are not an admin) offset = 8400 limit = 100 index = 0 i = 0 all_participants = [] client = TelegramClient('session_name', api_id, api_hash).start() ''' From documentation: Starting as an user account from code: client.start(phone, force_sms=true) phone = '+34 123 123 123' client.sign_in(phone) code = input('enter code: ') client.sign_in(phone, code) Auth ready code: client.connect() if not client.is_user_authorized(): client.send_code_request(phone, force_sms=true) client.sign_in(phone, auth_code) Logging out from Telegram account: client.log_out() P.S.:AND/OR: client.disconnect() ''' print('Start getting participants from some_crypto_group group...') all_participants = client.get_participants(channel, aggressive=True) print('Finded {} users'.format(all_participants.total)) our_channel = 'some_new_crypto_channel_or_group' for user in all_participants: if (index < 50 and i > offset): # Select users considering innitial offset and send no more than 50 invites from one Telegram account (because of some spam protection) print('Success: index - {} Name: {}'.format(i, user.first_name)) try: client(InviteToChannelRequest( our_channel, [user] )) index += 1 except PeerFloodError: print("Getting Flood Error from telegram.") # Here a program must sign out from Telegram account and then connect to another Telegram account. except: e = sys.exc_info() print(e) time.sleep(20) # An important line of code! It's a preventing of Flood Error exception (in the most of cases...) i += 1 ''' Using CSV (for storing phone numbers db): import csv with open(input_file, encoding='UTF-8') as f: rows = csv.reader(f,delimiter=",",lineterminator="\n") next(rows, None) for row in rows: user = {} user['username'] = row[0] (only example of simplest using of CSV in Python!) '''