-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathgensession.py
55 lines (48 loc) · 1.65 KB
/
gensession.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import asyncio
import os
from sys import executable, exit
try:
from pyrogram.errors import ApiIdInvalid, PhoneNumberInvalid
from pyrogram import Client
print("Found an existing installation of Pyrogram...\nSuccessfully Imported.")
except ImportError:
print("Installing Pyrogram...")
os.system(f"{executable} -m pip install pyrogram")
print("Done. Installed and imported pyrogram.")
from pyrogram.errors import ApiIdInvalid, PhoneNumberInvalid
from pyrogram import Client
async def main():
API_ID = 0
try:
API_ID = int(input("Please enter your API ID: "))
except ValueError:
print("APP ID must be an integer.\nQuitting...")
exit(0)
except Exception as e:
raise e
API_HASH = input("Please enter your API HASH: ")
try:
async with Client("pagermaid", API_ID, API_HASH) as bot:
print("Generating a user session...")
await bot.send_message(
"me",
f"**PagerMaid** `String SESSION`:\n\n`{await bot.export_session_string()}`",
)
print(
"Your SESSION has been generated. Check your telegram saved messages!"
)
exit(0)
except ApiIdInvalid:
print(
"Your API ID/API HASH combination is invalid. Kindly recheck.\nQuitting..."
)
exit(0)
except ValueError:
print("API HASH must not be empty!\nQuitting...")
exit(0)
except PhoneNumberInvalid:
print("The phone number is invalid!\nQuitting...")
exit(0)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())