Add .env configuration support
This commit is contained in:
26
main.py
26
main.py
@@ -2,15 +2,27 @@ import os
|
||||
import json
|
||||
import requests
|
||||
from jdatetime import datetime, timedelta
|
||||
from dotenv import load_dotenv
|
||||
|
||||
BARGHEMAN_TOKEN = os.getenv("BARGHEMAN_TOKEN")
|
||||
EITAAYAR_TOKEN = os.getenv("EITAAYAR_TOKEN")
|
||||
CHAT_ID = os.getenv("CHAT_ID")
|
||||
BILL_IDS = os.getenv("BILL_IDS", "").split(",")
|
||||
BLACKOUTS_FILE = os.getenv("BLACKOUTS_FILE")
|
||||
# Load local configuration without overriding variables supplied by the shell or CI.
|
||||
load_dotenv()
|
||||
|
||||
if not BARGHEMAN_TOKEN or not EITAAYAR_TOKEN or not CHAT_ID or len(BILL_IDS) == 0:
|
||||
raise EnvironmentError("Environment is not ready!")
|
||||
BARGHEMAN_TOKEN = os.getenv("BARGHEMAN_TOKEN", "").strip()
|
||||
EITAAYAR_TOKEN = os.getenv("EITAAYAR_TOKEN", "").strip()
|
||||
CHAT_ID = os.getenv("CHAT_ID", "").strip()
|
||||
BILL_IDS = [bill_id.strip() for bill_id in os.getenv("BILL_IDS", "").split(",") if bill_id.strip()]
|
||||
BLACKOUTS_FILE = os.getenv("BLACKOUTS_FILE", "").strip()
|
||||
|
||||
required_settings = {
|
||||
"BARGHEMAN_TOKEN": BARGHEMAN_TOKEN,
|
||||
"EITAAYAR_TOKEN": EITAAYAR_TOKEN,
|
||||
"CHAT_ID": CHAT_ID,
|
||||
"BILL_IDS": BILL_IDS,
|
||||
"BLACKOUTS_FILE": BLACKOUTS_FILE,
|
||||
}
|
||||
missing_settings = [name for name, value in required_settings.items() if not value]
|
||||
if missing_settings:
|
||||
raise EnvironmentError(f"Missing required environment variables: {', '.join(missing_settings)}")
|
||||
|
||||
today = datetime.now()
|
||||
to_date = today + timedelta(days=5)
|
||||
|
||||
Reference in New Issue
Block a user