Skip to content

Commit 118ef3c

Browse files
committed
bot: move .env to root dir
1 parent 1540838 commit 118ef3c

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

WWCS/irrigation/telegramBot/bot.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212
from databases import Database
1313
from telebot import types
1414
from telebot.async_telebot import AsyncTeleBot
15-
import dotenv
1615
import 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']
2221
BOT_TOKEN = os.environ['BOT_TOKEN']
2322
LANGUAGE = os.environ.get('LANGUAGE', 'en')
2423
TIMEZONE = 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'
2827
database = Database(DATABASE_URL)
2928

3029
# Initialize gettext
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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')

0 commit comments

Comments
 (0)