Skip to content

Commit 4a00122

Browse files
author
Adriano Sanges
committed
Refactor telegram_api.py to enhance environment variable loading
- Introduce a new function to load environment variables from multiple potential .env file locations - Add warning message if no .env file is found, improving error handling - Streamline the loading process for better configuration management
1 parent 733e834 commit 4a00122

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

real-estate-etl/telegram_api.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
from typing import Dict, Any
44
from dotenv import load_dotenv
55

6-
load_dotenv()
6+
def load_env_file():
7+
if os.path.exists("../.env"):
8+
load_dotenv("../.env")
9+
elif os.path.exists("../files/.env"):
10+
load_dotenv("../files/.env")
11+
else:
12+
print("Warning: No .env file found in ../.env or ../files/.env")
13+
14+
load_env_file()
715

816
TELEGRAM_BOT_API_KEY: str = os.getenv("telegram_bot_api_key")
917

0 commit comments

Comments
 (0)