Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
boomhq committed May 22, 2020
1 parent d410278 commit aa193f0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
Empty file added Models/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion betMODEL.py → Models/betMODEL.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class User(Base):
notify = Column(Integer)


schema = os.environ.get('betBOTSchema')
schema = os.environ.get('BET_BOT_SCHEMA')
engine = create_engine(schema)
Base.metadata.create_all(engine)

Expand Down
5 changes: 5 additions & 0 deletions Settings/.env.exemple
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ENV conf
BET_BOT_SCHEMA='sqlite:///db.sqlite'
BET_BOT_API_KEY=TELEGRAM_API_KEY
BET_BOT_LANG=fr
BET_BOT_ADMINS="[12412421, 4124124]"
Empty file added Settings/__init__.py
Empty file.
11 changes: 9 additions & 2 deletions betLANG.py → Settings/settings.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# Settings.py
import json
import os
from dotenv import load_dotenv

# Load .ENV
load_dotenv()

#Load Translation
texts = {}
lang = 'en'
path = os.path.dirname(os.path.abspath(__file__))


with open(path + '/lang.json') as json_data:
with open(path + '/../lang.json') as json_data:
texts = json.load(json_data)


def change_lang(lan='en'):
def change_lang(lan='fr'):
global lang
if texts.get(lan):
lang = lan
Expand All @@ -23,3 +29,4 @@ def gettext(string):
if texts.get(lang) and texts[lang].get(string):
return texts[lang][string]
return string

15 changes: 7 additions & 8 deletions betBOT.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@
import sys
import ast
import datetime
from Settings.settings import *

from telebot import TeleBot, types
from emoji import emojize
from betMODEL import Match, Ranking, Bet, User, get_matches, get_bets, \
from Models.betMODEL import Match, Ranking, Bet, User, get_matches, get_bets, \
get_users, get_ranking, add, update, delete, get_session
from betLANG import gettext, change_lang


token = os.environ.get('betBOT')
token = os.environ.get('BET_BOT_API_KEY')

#Getter for translation
_ = gettext

if not token:
sys.exit(_('Add an enviroment variable $betBOT with your token.'))

if sys.argv[1] and 'lang=' in sys.argv[1]:
lang = sys.argv[1].split('=')[1]
change_lang(lang)
lang = os.environ.get('BET_BOT_LANG')
change_lang(lang)

if sys.argv[2] and 'admins=' in sys.argv[2]:
administrators = ast.literal_eval(sys.argv[2][7:])
administrators = ast.literal_eval(os.environ.get('BET_BOT_ADMINS'))


bot = TeleBot(token)
Expand Down

0 comments on commit aa193f0

Please sign in to comment.