Fred808 commited on
Commit
a2bd71e
·
verified ·
1 Parent(s): c47e96a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -30,17 +30,34 @@ logging.basicConfig(
30
  ]
31
  )
32
 
 
33
  # === Setup Telegram Client (only if credentials are available) ===
34
  client = None
35
  if API_ID and API_HASH:
36
  try:
37
- session_path = os.path.expanduser("~/my_session") if not os.path.exists("my_session.session") else "my_session"
38
- logging.info(f"Using session path: {session_path}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  client = TelegramClient(session_path, int(API_ID), API_HASH)
 
40
  except ValueError as e:
41
- logging.error(f"Failed to initialize Telegram client: {e}")
42
  client = None
43
 
 
44
  # === Ensure download folder exists ===
45
  os.makedirs("downloads", exist_ok=True)
46
 
 
30
  ]
31
  )
32
 
33
+ # === Setup Telegram Client (only if credentials are available) ===
34
  # === Setup Telegram Client (only if credentials are available) ===
35
  client = None
36
  if API_ID and API_HASH:
37
  try:
38
+ # First, check if session exists in current directory
39
+ session_path = "my_session"
40
+ session_file = "my_session.session"
41
+
42
+ if not os.path.exists(session_file):
43
+ # Try home directory if not found in CWD
44
+ home_session = os.path.expanduser("~/my_session.session")
45
+ if os.path.exists(home_session):
46
+ session_path = os.path.expanduser("~/my_session")
47
+ logging.info(f"✅ Found session in home dir: {home_session}")
48
+ else:
49
+ logging.warning("⚠️ No session file found in current dir or home dir. Will try to connect unauthenticated.")
50
+
51
+ else:
52
+ logging.info(f"✅ Found session in current directory: {session_file}")
53
+
54
  client = TelegramClient(session_path, int(API_ID), API_HASH)
55
+
56
  except ValueError as e:
57
+ logging.error(f"Failed to initialize Telegram client: {e}")
58
  client = None
59
 
60
+
61
  # === Ensure download folder exists ===
62
  os.makedirs("downloads", exist_ok=True)
63