File tree Expand file tree Collapse file tree 2 files changed +33
-5
lines changed
WWCS/irrigation/telegramBot Expand file tree Collapse file tree 2 files changed +33
-5
lines changed Original file line number Diff line number Diff line change 1212from databases import Database
1313from telebot import types
1414from telebot .async_telebot import AsyncTeleBot
15- import dotenv
1615import traceback
1716
17+ from common import USERNAME , PASSWORD
18+
19+
1820# Configuration
19- dotenv .load_dotenv ()
20- DB_USERNAME = os .environ .get ('DB_USERNAME' , 'root' )
21- DB_PASSWORD = os .environ ['DB_PASSWORD' ]
2221BOT_TOKEN = os .environ ['BOT_TOKEN' ]
2322LANGUAGE = os .environ .get ('LANGUAGE' , 'en' )
2423TIMEZONE = os .environ .get ('TIMEZONE' ) # Defaults to local timezone
2524
2625# Database
27- DATABASE_URL = f'mysql+asyncmy://{ DB_USERNAME } :{ DB_PASSWORD } @localhost:3306/SitesHumans'
26+ DATABASE_URL = f'mysql+asyncmy://{ USERNAME } :{ PASSWORD } @localhost:3306/SitesHumans'
2827database = Database (DATABASE_URL )
2928
3029# Initialize gettext
Original file line number Diff line number Diff line change 1+ import os
2+ import pathlib
3+
4+ import dotenv
5+
6+
7+ def get_rootdir ():
8+ """
9+ Returns the absolute path to the project's root directory (or working directory in
10+ Git's parlance).
11+ """
12+ current_dir = pathlib .Path (__file__ ).parent .resolve ()
13+ while current_dir != current_dir .parent :
14+ env_path = current_dir / '.git'
15+ if env_path .exists ():
16+ return current_dir
17+
18+ current_dir = current_dir .parent
19+
20+
21+ # Load the .env file, in production this must be /home/wwcs/wwcs/.env
22+ # Or more generally {ROOT-DIRECTORY}/.env (in local development the root directory
23+ # may be somewhere else than /home/wwcs/wwcs)
24+ ROOT_DIR = get_rootdir ()
25+ dotenv .load_dotenv (ROOT_DIR / '.env' )
26+
27+
28+ USERNAME = os .environ .get ('DB_USERNAME' , 'wwcs' )
29+ PASSWORD = os .environ .get ('DB_PASSWORD' )
You can’t perform that action at this time.
0 commit comments