diff --git a/config.sample.yml b/config.sample.yml deleted file mode 100644 index 8f3ad55..0000000 --- a/config.sample.yml +++ /dev/null @@ -1,4 +0,0 @@ -token: my_telegram_bot_token - -watchlist: - max_items: 8 \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index d8b9c97..3bf1de8 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -3,6 +3,6 @@ version: '3.7' services: bot: build: . + env_file: .dev.env volumes: - - ./data.db:/app/data.db - - ./config.yml:/app/config.yml:ro + - ./data:/app/data \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 8fb709c..e7453a4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,8 @@ services: bot: image: cupcakearmy/mercatus restart: unless-stopped + environment: + - TOKEN=my_token + - MAX_LIST_SIZE=8 volumes: - - ./data.db:/app/data.db - - ./config.yml:/app/config.yml:ro + - ./data:/app/data \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5799cd8..21b25a8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,4 @@ alpha-vantage==2.1.* matplotlib==3.1.* numpy==1.18.* pandas==0.25.* -python-telegram-bot==12.2.* -PyYAML==5.* \ No newline at end of file +python-telegram-bot==12.2.* \ No newline at end of file diff --git a/src/commands/watchlist.py b/src/commands/watchlist.py index d4ee505..0c7da51 100644 --- a/src/commands/watchlist.py +++ b/src/commands/watchlist.py @@ -4,7 +4,7 @@ from telegram.ext import CallbackContext, ConversationHandler, CommandHandler, C from commands.other import send_update_to_user from constants import Section from limited_dict import LimitedDict -from utils import config +from utils import max_list_items ALL, SINGLE, EDIT, ADD, DELETE, BACK, ENABLED, FREQUENCY, INTERVAL, DATA = map(chr, range(10)) END = str(ConversationHandler.END) @@ -12,7 +12,7 @@ END = str(ConversationHandler.END) def get_watchlist(context: CallbackContext) -> LimitedDict: return LimitedDict( - config[Section.Watchlist.value]['max_items'], + max_list_items, context.user_data.setdefault(Section.Watchlist.value, {}), ) diff --git a/src/utils.py b/src/utils.py index b335fc2..7e52ce9 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,15 +1,27 @@ from datetime import datetime, timedelta +from os import environ, makedirs +from os.path import exists, dirname from telegram import Update from telegram.ext import PicklePersistence, Updater -from yaml import load, Loader -DB_FILE = './data.db' -CONFIG_FILE = './config.yml' +DB_FILE = './data/db.pickle' +DB_DIR = dirname(DB_FILE) + +if not exists(DB_DIR): + makedirs(DB_DIR) + +try: + max_list_items = int(environ.get('MAX_LIST_SIZE')) +except: + max_list_items = 8 + +token = environ.get('TOKEN') +if not token: + raise Exception('No Token found.') -config = load(open(CONFIG_FILE, 'r'), Loader=Loader) persistence = PicklePersistence(DB_FILE) -updater: Updater = Updater(config['token'], use_context=True, persistence=persistence) +updater: Updater = Updater(token, use_context=True, persistence=persistence) def update_updater_data():