Ejemplo n.º 1
0
def paginater(page, per_page):
    total_count = Users.select(Users.telegram_id).order_by(Users.telegram_id).count()
    pagsss = int(ceil(total_count / float(per_page)))
    print(f'Page - {page}, Pages - {pagsss}, Per Page - {per_page}, COUNT - {total_count}')
    if page > pagsss:
        return 'много'
    return [i for i in Users.select().paginate(page, per_page)]
Ejemplo n.º 2
0
def add_user(id_tg, name, sub=False):
    user = Users.get_or_none(id_tg)
    if user:
        return user
    user = Users.create(telegram_id=id_tg, name=name, sub=sub)
    logger.info(f'Пользователь создан: {id_tg}-{name}, {user}')
    return user
Ejemplo n.º 3
0
def get_keyboard(id_tg):
    user = Users.get_or_none(id_tg)
    if not user:
        user = Users()
    kb = ReplyKeyboardMarkup(resize_keyboard=True,
                             one_time_keyboard=True,
                             keyboard=[[
                                 KeyboardButton('/help'),
                                 KeyboardButton('/check'),
                                 KeyboardButton('/add') if not user.telegram_id
                                 else KeyboardButton('/del'),
                                 KeyboardButton('/subt')
                                 if not user.sub else KeyboardButton('/subf')
                             ], [KeyboardButton('Cancel')]])
    return kb
Ejemplo n.º 4
0
def del_user(id_tg):
    user = Users.get_or_none(id_tg)
    if user:
        user.delete_by_id(id_tg)
        logger.info(f'Пользователь удален: {user} в {datetime.datetime.now()}')
        return True
    return False
Ejemplo n.º 5
0
def get_keyboard_expense():
    user = Users.get_user(468933460)
    expens = Expenses.select().where(Expenses.user == user)
    keyIN = InlineKeyboardMarkup(row_width=2)
    for i in expens:
        keyIN.add(InlineKeyboardButton(text=f'{i.id}: {i.category.category} - {i.text_mes}',
                                       callback_data=cdb_menu_expenses.new(id=i.id)))

    return keyIN
Ejemplo n.º 6
0
def swap_sub(id_tg):
    user = Users.get_or_none(id_tg)
    if user.sub:
        user.sub = False
        user.save(only=[Users.sub])
        return user.sub
    user.sub = True
    user.save(only=[Users.sub])
    return user.sub
Ejemplo n.º 7
0
def get_user(id_tg: int) -> Users or None:
    return Users.get_or_none(id_tg)
Ejemplo n.º 8
0
def select_all_user():
    sel = Users.select().order_by(Users.telegram_id)
    print(sel)
    for i in sel:
        print(i)
Ejemplo n.º 9
0
def check_for_user_sub(id_tg):
    try:
        Users.select().where(Users.telegram_id == id_tg, Users.sub >> True).get()
        return True
    except DoesNotExist:
        return False