Exemple #1
0
def handler_statistics(update: Update, context: CallbackContext):
    query = update.callback_query
    request = query.data
    user = session.query(User).filter(
        User.telegram_user_id == update.effective_user.id).first()
    graph_controller = context.user_data.get('statistics')
    if not graph_controller:
        graph_controller = GraphController(
            make_default_graph(user),
            get_lifetime_user(user, datetime.datetime.now()),
            TypeTransaction.CONSUMPTION)
        context.user_data['statistics'] = graph_controller
    if request == '{}earnings'.format(prefix_query_statistics):
        graph_controller.update_type_transactions(TypeTransaction.EARNING)
        handler_button_choose_type_transactions(update, context, user)
    elif request == '{}consumptions'.format(prefix_query_statistics):
        graph_controller.update_type_transactions(TypeTransaction.CONSUMPTION)
        handler_button_choose_type_transactions(update, context, user)
    elif request == '{}time_period'.format(prefix_query_statistics):
        media_object = InputMediaPhoto(
            open(graph_controller.path_to_current_graph, 'rb'))
        bot.edit_message_media(chat_id=query.message.chat_id,
                               message_id=query.message.message_id,
                               media=media_object,
                               reply_markup=reply_keyboard_choose_time_period)
    elif request == '{}yesterday'.format(prefix_query_statistics):
        graph_controller.update_time_period(
            get_yesterday(datetime.datetime.now()))
        handler_button_choose_time_period(update, context, user)
    elif request == '{}today'.format(prefix_query_statistics):
        graph_controller.update_time_period(get_today(datetime.datetime.now()))
        handler_button_choose_time_period(update, context, user)
    elif request == '{}current_week'.format(prefix_query_statistics):
        graph_controller.update_time_period(
            get_current_week(datetime.datetime.now()))
        handler_button_choose_time_period(update, context, user)
    elif request == '{}current_month'.format(prefix_query_statistics):
        graph_controller.update_time_period(
            get_current_month(datetime.datetime.now()))
        handler_button_choose_time_period(update, context, user)
    elif request == '{}all_time'.format(prefix_query_statistics):
        graph_controller.update_time_period(
            get_lifetime_user(user, datetime.datetime.now()))
        handler_button_choose_time_period(update, context, user)
    elif request == '{}back'.format(prefix_query_statistics):
        media_object = InputMediaPhoto(
            open(graph_controller.path_to_current_graph, 'rb'))
        bot.edit_message_media(
            chat_id=update.callback_query.message.chat_id,
            message_id=update.callback_query.message.message_id,
            media=media_object,
            reply_markup=reply_main_keyboard)
Exemple #2
0
def make_default_graph(user):
    time_period = get_lifetime_user(user, now=datetime.datetime.now())
    data, labels = get_transactions_for_graph_by_type(
        session, user, TypeTransaction.CONSUMPTION, time_period)
    path_to_graph = make_pie_graph(data, labels, time_period,
                                   TypeTransaction.CONSUMPTION)
    return path_to_graph
Exemple #3
0
def entry_point_statistics(update: Update, context: CallbackContext):
    user = session.query(User).filter(
        User.telegram_user_id == update.message.from_user.id).first()
    path_to_graph = make_default_graph(user)
    graph_controller = GraphController(
        path_to_graph, get_lifetime_user(user, now=datetime.datetime.now()),
        TypeTransaction.CONSUMPTION)
    context.user_data['statistics'] = graph_controller
    bot.send_photo(chat_id=update.message.from_user.id,
                   photo=open(path_to_graph, 'rb'),
                   reply_markup=reply_main_keyboard)
Exemple #4
0
def handler_export(update: Update, context: CallbackContext):
    user = session.query(User).filter(
        User.telegram_user_id == update.message.from_user.id).first()
    xls_maker = XlsMaker(user)
    xls = xls_maker.make_xlx_file()
    with tempfile.TemporaryDirectory() as tmpdirname:
        save_path = os.path.join(
            tmpdirname,
            "{}.xlsx".format(get_lifetime_user(user, datetime.datetime.now())))
        xls.save(save_path)
        bot.send_document(chat_id=update.message.from_user.id,
                          document=open(save_path, 'rb'))
Exemple #5
0
 def _make_head(self):
     self.ws.title = get_lifetime_user(self.user, datetime.datetime.now())
     ft_red = Font(color=colors.RED)
     ft_green = Font(color=colors.GREEN)
     self.ws['A1'] = 'РАСХОДЫ'
     self.ws['A2'] = 'Дата'
     self.ws['B2'] = 'Категория'
     self.ws['C2'] = 'Кол-во денег'
     self.ws['E1'] = 'ДОХОДЫ'
     self.ws['E2'] = 'Дата'
     self.ws['F2'] = 'Категория'
     self.ws['G2'] = 'Кол-во денег'
     for col in self.ws.columns:
         col[0].font = Font(bold=True)
         col[1].font = Font(bold=True)
     self.ws['A1'].font = ft_red
     self.ws['E1'].font = ft_green