mirror of
https://github.com/cupcakearmy/mercatus.git
synced 2024-12-22 16:16:32 +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:
|
services:
|
||||||
bot:
|
bot:
|
||||||
build: .
|
build: .
|
||||||
|
env_file: .dev.env
|
||||||
volumes:
|
volumes:
|
||||||
- ./data.db:/app/data.db
|
- ./data:/app/data
|
||||||
- ./config.yml:/app/config.yml:ro
|
|
@ -4,6 +4,8 @@ services:
|
|||||||
bot:
|
bot:
|
||||||
image: cupcakearmy/mercatus
|
image: cupcakearmy/mercatus
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
- TOKEN=my_token
|
||||||
|
- MAX_LIST_SIZE=8
|
||||||
volumes:
|
volumes:
|
||||||
- ./data.db:/app/data.db
|
- ./data:/app/data
|
||||||
- ./config.yml:/app/config.yml:ro
|
|
@ -4,4 +4,3 @@ matplotlib==3.1.*
|
|||||||
numpy==1.18.*
|
numpy==1.18.*
|
||||||
pandas==0.25.*
|
pandas==0.25.*
|
||||||
python-telegram-bot==12.2.*
|
python-telegram-bot==12.2.*
|
||||||
PyYAML==5.*
|
|
@ -4,7 +4,7 @@ from telegram.ext import CallbackContext, ConversationHandler, CommandHandler, C
|
|||||||
from commands.other import send_update_to_user
|
from commands.other import send_update_to_user
|
||||||
from constants import Section
|
from constants import Section
|
||||||
from limited_dict import LimitedDict
|
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))
|
ALL, SINGLE, EDIT, ADD, DELETE, BACK, ENABLED, FREQUENCY, INTERVAL, DATA = map(chr, range(10))
|
||||||
END = str(ConversationHandler.END)
|
END = str(ConversationHandler.END)
|
||||||
@ -12,7 +12,7 @@ END = str(ConversationHandler.END)
|
|||||||
|
|
||||||
def get_watchlist(context: CallbackContext) -> LimitedDict:
|
def get_watchlist(context: CallbackContext) -> LimitedDict:
|
||||||
return LimitedDict(
|
return LimitedDict(
|
||||||
config[Section.Watchlist.value]['max_items'],
|
max_list_items,
|
||||||
context.user_data.setdefault(Section.Watchlist.value, {}),
|
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 datetime import datetime, timedelta
|
||||||
|
from os import environ, makedirs
|
||||||
|
from os.path import exists, dirname
|
||||||
|
|
||||||
from telegram import Update
|
from telegram import Update
|
||||||
from telegram.ext import PicklePersistence, Updater
|
from telegram.ext import PicklePersistence, Updater
|
||||||
from yaml import load, Loader
|
|
||||||
|
|
||||||
DB_FILE = './data.db'
|
DB_FILE = './data/db.pickle'
|
||||||
CONFIG_FILE = './config.yml'
|
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)
|
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():
|
def update_updater_data():
|
||||||
|
Loading…
Reference in New Issue
Block a user