Skip to content

Commit

Permalink
______
Browse files Browse the repository at this point in the history
  • Loading branch information
subinps authored Jun 17, 2021
1 parent 36c9e97 commit b2fc265
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions generate_instagram_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,62 +26,77 @@
import asyncio
import os
from instaloader import Instaloader, TwoFactorAuthRequiredException

L = Instaloader()


async def generate():
print("Enter your Telegram API_ID")
API_ID=input()
API_ID = input()
print("Enter API_HASH")
API_HASH=input()
API_HASH = input()
print("Enter Your BOT_TOKEN from Botfather")
BOT_TOKEN=input()
BOT_TOKEN = input()

bot = Client("INSTASESSION", API_ID, API_HASH, bot_token=BOT_TOKEN)
await bot.start()
print("Now Enter your Instagram username")
id=input()
id = input()
print("Enter Your Instagram Password")
pwd=input()
pwd = input()
try:
L.login(id, pwd)
L.save_session_to_file(filename=f"./{id}")
except TwoFactorAuthRequiredException:
print("Your account has Two Factor authentication Enabled.\nNow Enter the code recived on your mobile.")
code=input()
print(
"Your account has Two Factor authentication Enabled.\nNow Enter the code recived on your mobile."
)
code = input()
L.two_factor_login(code)
L.save_session_to_file(filename=f"./{id}")
except Exception as e:
print(e)
return
print("Succesfully Logged into Instagram")
while True:
print("To send your Session file enter Your Telegram ID as Integer")
tg_id=input()
tg_id = input()
try:
owner=int(tg_id)
owner = int(tg_id)
break
except:
print("Oops Thats Invalid, Enter ID as Integer")
try:
f=await bot.send_document(
f = await bot.send_document(
chat_id=owner,
document=f"./{id}",
file_name=tg_id,
caption="⚠️ KEEP THIS SESSION FILE SAFE AND DO NOT SHARE WITH ANYBODY",
)
file_id=f.document.file_id
caption=
"⚠️ KEEP THIS SESSION FILE SAFE AND DO NOT SHARE WITH ANYBODY",
)
file_id = f.document.file_id
await bot.send_message(
chat_id=owner,
text=f"Here is Your <code>INSTA_SESSIONFILE_ID</code>\n\n<code>{file_id}</code>\n\n\n⚠️ KEEP THIS SESSION FILE SAFE AND DO NOT SHARE WITH ANYBODY"
)
print("I have messaged you the INSTA_SESSIONFILE_ID. Check your telegram messages")
text=
f"Here is Your <code>INSTA_SESSIONFILE_ID</code>\n\n<code>{file_id}</code>\n\n\n⚠️ KEEP THIS SESSION FILE SAFE AND DO NOT SHARE WITH ANYBODY"
)
print(
"I have messaged you the INSTA_SESSIONFILE_ID. Check your telegram messages"
)
except PeerIdInvalid:
print("It seems you have not yet started the bot or Telegram ID given is invalid. Send /start to your bot first and try again")
print(
"It seems you have not yet started the bot or Telegram ID given is invalid. Send /start to your bot first and try again"
)
except UserIsBlocked:
print("It seems you have BLOCKED the Bot. Unblock the bot and try again.")
print(
"It seems you have BLOCKED the Bot. Unblock the bot and try again."
)
except Exception as e:
print(e)
print(e)
await bot.stop()
os.remove(f"./{id}")
os.remove("INSTASESSION.session")


loop = asyncio.get_event_loop()
loop.run_until_complete(generate())
loop.run_until_complete(generate())

0 comments on commit b2fc265

Please sign in to comment.