Skip to content

Commit 76ccc7d

Browse files
committed
Add dotenv support for environment-based settings
Integrated python-dotenv to load environment variables and updated Settings to use values from either the provided dictionary or environment. Added python-dotenv to requirements.txt.
1 parent 69bea8e commit 76ccc7d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

addons/settings.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,26 @@
2121
SOFTWARE.
2222
"""
2323

24+
import os
25+
26+
from dotenv import load_dotenv
2427
from typing import (
2528
Dict,
2629
List,
2730
Any,
2831
Union
2932
)
3033

34+
load_dotenv()
35+
3136
class Settings:
3237
def __init__(self, settings: Dict) -> None:
33-
self.token: str = settings.get("token")
34-
self.client_id: int = int(settings.get("client_id", 0))
35-
self.genius_token: str = settings.get("genius_token")
36-
self.mongodb_url: str = settings.get("mongodb_url")
37-
self.mongodb_name: str = settings.get("mongodb_name")
38+
print(os.environ)
39+
self.token: str = settings.get("token") or os.getenv("TOKEN")
40+
self.client_id: int = int(settings.get("client_id", 0)) or int(os.getenv("CLIENT_ID"))
41+
self.genius_token: str = settings.get("genius_token") or os.getenv("GENIUS_TOKEN")
42+
self.mongodb_url: str = settings.get("mongodb_url") or os.getenv("MONGODB_URL")
43+
self.mongodb_name: str = settings.get("mongodb_name") or os.getenv("MONGODB_NAME")
3844

3945
self.invite_link: str = "https://discord.gg/wRCgB7vBQv"
4046
self.nodes: Dict[str, Dict[str, Union[str, int, bool]]] = settings.get("nodes", {})

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ validators==0.18.2
66
humanize==4.0.0
77
beautifulsoup4==4.11.1
88
psutil==5.9.8
9-
aiohttp==3.11.12
9+
aiohttp==3.11.12
10+
python-dotenv==1.1.1

0 commit comments

Comments
 (0)