Skip to content

Instantly share code, notes, and snippets.

@SmartManoj
Created December 28, 2020 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SmartManoj/0f5caf0556645beaa7bdadd6ad7ca75f to your computer and use it in GitHub Desktop.
Save SmartManoj/0f5caf0556645beaa7bdadd6ad7ca75f to your computer and use it in GitHub Desktop.
import csv
import random
from telethon import TelegramClient, events, sync
from telethon.tl.types import InputPhoneContact
from telethon import functions, types
api_id = 210829
api_hash = '..'
client = TelegramClient('SmartManoj2', api_id, api_hash)
with open('contacts.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
first_name, last_name, phone = row
contact = InputPhoneContact(random.randint(0, 9999), phone, first_name, last_name)
contacts = client(functions.contacts.ImportContactsRequest([contact]))
a1 = contacts.to_dict()['users'][0]['username']
a2 = contacts.to_dict()['users'][0]['phone']
a3 = contacts.to_dict()['users'][0]['id']
print(a1, a2, a3, file=open('tlogs', 'a'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment