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.
This commit is contained in:
@@ -21,6 +21,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from typing import (
|
||||
Dict,
|
||||
List,
|
||||
@@ -28,13 +31,16 @@ from typing import (
|
||||
Union
|
||||
)
|
||||
|
||||
load_dotenv()
|
||||
|
||||
class Settings:
|
||||
def __init__(self, settings: Dict) -> None:
|
||||
self.token: str = settings.get("token")
|
||||
self.client_id: int = int(settings.get("client_id", 0))
|
||||
self.genius_token: str = settings.get("genius_token")
|
||||
self.mongodb_url: str = settings.get("mongodb_url")
|
||||
self.mongodb_name: str = settings.get("mongodb_name")
|
||||
print(os.environ)
|
||||
self.token: str = settings.get("token") or os.getenv("TOKEN")
|
||||
self.client_id: int = int(settings.get("client_id", 0)) or int(os.getenv("CLIENT_ID"))
|
||||
self.genius_token: str = settings.get("genius_token") or os.getenv("GENIUS_TOKEN")
|
||||
self.mongodb_url: str = settings.get("mongodb_url") or os.getenv("MONGODB_URL")
|
||||
self.mongodb_name: str = settings.get("mongodb_name") or os.getenv("MONGODB_NAME")
|
||||
|
||||
self.invite_link: str = "https://discord.gg/wRCgB7vBQv"
|
||||
self.nodes: Dict[str, Dict[str, Union[str, int, bool]]] = settings.get("nodes", {})
|
||||
|
||||
@@ -6,4 +6,5 @@ validators==0.18.2
|
||||
humanize==4.0.0
|
||||
beautifulsoup4==4.11.1
|
||||
psutil==5.9.8
|
||||
aiohttp==3.11.12
|
||||
aiohttp==3.11.12
|
||||
python-dotenv==1.1.1
|
||||
Reference in New Issue
Block a user