-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
59 lines (44 loc) · 1.58 KB
/
main.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
56
57
import os
from dotenv import load_dotenv
from pyrogram import Client
# Load environment variables from .env file if present
load_dotenv()
def get_input_or_env(variable_name, prompt):
value = os.getenv(variable_name)
if not value:
value = input(prompt)
return value
# Function to generate the session string
def export_session_string():
# Get API ID
API_ID = get_input_or_env("API_ID", "Enter your API ID: ")
# Get API Hash
API_HASH = get_input_or_env("API_HASH", "Enter your API Hash: ")
# Get phone number
PHONE_NUMBER = get_input_or_env("PHONE_NUMBER", "Enter your phone number (with country code): ")
SESSION_STRING = "my_session"
try:
app = Client(
name=SESSION_STRING,
api_id=API_ID,
api_hash=API_HASH,
phone_number=PHONE_NUMBER
)
with app:
session_string = app.export_session_string()
print("Session string generated successfully!\n")
print("Your session string is:\n")
print(session_string)
# Define the session file path
session_file = f"{SESSION_STRING}.session"
# Check if the session file exists and delete it
if os.path.exists(session_file):
os.remove(session_file)
print(f"\nSession file '{session_file}' has been deleted.")
else:
print(f"\nSession file '{session_file}' not found.")
except Exception as e:
print(f"An error occurred: {e}")
# Run the function
if __name__ == "__main__":
export_session_string()