Example #1
0
 def test_4_set_is_login(self):
     chat_id = 1010
     auxiliar.create_db()
     auxiliar.create_user(chat_id)
     self.assertFalse(auxiliar.check_value(chat_id, "IS_LOGIN", "STATUS"))
     auxiliar.set_is_login(chat_id)
     self.assertTrue(auxiliar.check_value(chat_id, "IS_LOGIN", "STATUS"))
Example #2
0
 def test_2_create_db(self):
     auxiliar.create_db()
     conn = auxiliar.get_db()
     cursor = conn.execute("SELECT * FROM USER;")
     conn.commit()
     users = cursor.fetchall()
     conn.close()
     self.assertTrue(len(users) == 0)
Example #3
0
 def test_6_save_value(self):
     chat_id = 1010
     token = 9999
     auxiliar.create_db()
     auxiliar.create_user(chat_id)
     self.assertIsNone(auxiliar.check_value(chat_id, "TOKEN", "USER"))
     auxiliar.save_value(chat_id, token, "TOKEN", "USER")
     self.assertTrue(
         auxiliar.check_value(chat_id, "TOKEN", "USER") == str(token))
Example #4
0
 def test_3_create_user(self):
     chat_id = 1010
     auxiliar.create_db()
     self.assertIsNone(auxiliar.check_user(chat_id))
     auxiliar.create_user(chat_id)
     self.assertIsNotNone(auxiliar.check_user(chat_id))
Example #5
0
import logging
from telebot import types


logging.basicConfig(filename="file.log", filemode='w', level=logging.INFO,
                    format='[%(levelname)s] - %(asctime)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S')

try:
    TELEGRAM_TOKEN = json.load(open('data.json'))['telegram-token']
    logging.info("TELEGRAM_TOKEN cargado correctamente.")
    CREATE_DB_COMMAND = json.load(open('data.json'))['create-db-command']
    logging.info("CREATE_DB_COMMAND cargado correctamente.")
    bot = telebot.TeleBot(TELEGRAM_TOKEN)
    logging.info("Bot @%s conectado correctamente." % str(bot.get_me().username))
    BASE_URL = json.load(open('data.json'))['base-url']
    auxiliar.create_db()
except Exception as e:
    logging.error("Ha ocurrido un problema durante la inicialización.", exc_info=True)

@bot.message_handler(commands=[CREATE_DB_COMMAND])
def reset_database(message):
    try:
        auxiliar.reset_db(bot, message)
    except Exception as e:
        logging.error("Ha ocurrido un problema al restaurar la base de datos.", exc_info=True)

@bot.message_handler(commands=['start'])
def send_welcome(message):
    try:
        user = auxiliar.check_user(message.from_user.id)
        if user is None: