mirror of
https://github.com/cupcakearmy/mercatus.git
synced 2024-12-21 23:56:26 +00:00
dropped yaml file and dependency for 2 env vars
This commit is contained in:
parent
c45b5fcdaa
commit
5acf02e3d2
@ -1,4 +0,0 @@
|
||||
token: my_telegram_bot_token
|
||||
|
||||
watchlist:
|
||||
max_items: 8
|
@ -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
|
@ -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
|
@ -3,5 +3,4 @@ alpha-vantage==2.1.*
|
||||
matplotlib==3.1.*
|
||||
numpy==1.18.*
|
||||
pandas==0.25.*
|
||||
python-telegram-bot==12.2.*
|
||||
PyYAML==5.*
|
||||
python-telegram-bot==12.2.*
|
@ -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, {}),
|
||||
)
|
||||
|
||||
|
22
src/utils.py
22
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():
|
||||
|
Loading…
Reference in New Issue
Block a user