예제 #1
0
def confirm_sub(bot, telegram):
    # statTime = time.strftime("%y%m")
    # statTime += '01'

    try:
        price_water = []
        add_sub(
            **{
                'telegram':
                telegram,
                'name':
                users[telegram].get('name'),
                'phone':
                users[telegram].get('phone'),
                'price':
                users[telegram]['price'],
                'term':
                users[telegram]['term'],
                'quantity':
                users[telegram]['how_much_sub'],
                'sum': (int(users[telegram]['price']) *
                        int(users[telegram]['how_much_sub'])),
                'econom': (int(users[telegram].get('how_much_sub')) *
                           (int(product_price.get('water')) -
                            int(users[telegram]['price']))),
                'street':
                users[telegram].get('street')
            })
        summa = int(users[telegram]['price']) * int(
            users[telegram]['how_much_sub']) * 100
        price_water.append(
            LabeledPrice(label=users[telegram]['term'], amount=summa))
        prices.update({telegram: price_water})
    except Exception as e:
        print('e', e)
        return back_to_main_menu_del(bot, telegram)
    try:
        text = FOR_SEND_SUB_TO_OTHER_BOT.format(
            telegram, users[telegram].get('name'),
            users[telegram].get('phone'), users[telegram]['term'],
            users[telegram]['price'], users[telegram]['how_much_sub'],
            (int(users[telegram]['price']) *
             int(users[telegram]['how_much_sub'])),
            (int(users[telegram].get('how_much_sub')) *
             (int(product_price.get('water')) -
              int(users[telegram]['price']))), users[telegram].get('street'))
    except Exception as e:
        print(e)
        return back_to_main_menu_del(bot, telegram)
    report(text)
    try:
        users[telegram].update(report=text)
    except Exception as e:
        back_to_main_menu_del(bot, telegram)
    pay_menu(bot, telegram)
예제 #2
0
def min_plu_of_sub(bot, telegram, act, call_id):
    try:
        if act == '-':
            if users[telegram]['how_much_sub'] <= users[telegram]['min_sub']:
                users[telegram]['how_much_sub'] = users[telegram]['min_sub']
                alert(
                    bot, call_id,
                    'Извиняй, {}бут это минимально возможное количество на {}'.
                    format(users[telegram]['min_sub'],
                           users[telegram]['term']))
            else:
                users[telegram]['how_much_sub'] -= 1
        else:
            try:
                users[telegram]['how_much_sub'] += 1
            except Exception as e:
                return back_to_main_menu_del(bot, telegram)
    except Exception as e:
        return back_to_main_menu_del(bot, telegram)

    users_menu = select_menu(telegram)
    try:
        edit_caption_of_photo(
            bot,
            SHOW_SUB.format(users[telegram]['price'], users[telegram]['term'],
                            users[telegram]['how_much_sub'],
                            (users[telegram]['how_much_sub'] *
                             int(users[telegram]['price'])),
                            (users[telegram]['how_much_sub'] *
                             (int(product_price.get('water')) -
                              int(users[telegram]['price'])))), telegram,
            users_menu.get('message_id'), 13)
    except Exception as e:
        print('error', e)
예제 #3
0
def replay_order(bot, telegram):
    last_order = select_last_street(telegram)
    last_order.pop('order_number')
    users.update({last_order.get('telegram'): last_order})
    users[telegram].update(water=last_order.get('amount'))
    text_for_confirm = DATES_FOR_CONFIRM.format(users[telegram].get('name'),
                                                users[telegram].get('phone'),
                                                users[telegram].get('street'))
    total = 1
    if users[telegram].get('water'):
        text_for_confirm += BOTTLE_FOR_CONFIRM.format(
            users[telegram].get('water'), product_price.get('water'),
            (users[telegram].get('water') * int(product_price.get('water'))))
        total = users[telegram].get('water') * int(product_price.get('water'))
    text_for_confirm += ITOG_CONFIRM.format(total)
    reply_message(bot, telegram,
                  select_menu(telegram).get('message_id'), text_for_confirm, 8)
예제 #4
0
def show_selected_bottles(bot, telegram, product, index):
    message_id = select_menu(telegram).get('message_id')
    print('here')
    try:
        send_photo(
            bot, telegram, WATER_PHOTO,
            NAME_OF_GOOD.format(product_name.get(product)) + GOOD.format(
                users[telegram].get(product), product_price.get(product),
                (users[telegram].get(product) *
                 int(product_price.get(product)))), index)
    except Exception as e:
        return back_to_main_menu_del(bot, telegram)

    try:
        del_menu(bot, telegram, message_id)
    except Exception as e:
        print('error', e)
    return True
예제 #5
0
def build_orders(orders):
    text = ''
    max_orders = 10
    for order in orders:
        text += ORDER_NUMBER % order.get('order_number') + \
                DATES_FOR_CONFIRM.format(order.get('name'), order.get('phone'), order.get('street')) + \
                BASKET_ORDERS.format(order.get('goods'), str(order.get('amount')),
                                     product_price.get(order.get('goods')), str(order.get('sum')), order.get('added'))

        if max_orders == 0:
            break
        max_orders -= 1
    return text
예제 #6
0
def min_plu(bot, telegram, product, act, call_id, index):
    try:
        if act == '+':
            users[telegram][product] += 1
        else:
            if users[telegram][product] == 1:
                users[telegram][product] = 1
                alert(bot, call_id, 'Извиняй, половинку не продаем')
            else:
                users[telegram][product] -= 1
    except Exception as e:
        return back_to_main_menu_del(bot, telegram)
    users_menu = select_menu(telegram)
    try:
        edit_caption_of_photo(
            bot,
            NAME_OF_GOOD.format(product_name.get(product)) + GOOD.format(
                users[telegram][product], product_price.get(product),
                (users[telegram][product] * int(product_price.get(product)))),
            telegram, users_menu.get('message_id'), index)
    except Exception as e:
        print('error', e)
예제 #7
0
def show_confirm_sub_water(bot, telegram, where=True):
    text = ''
    message_id = select_menu(telegram).get('message_id')
    try:
        text = SHOW_SUB_FOR_CONFIRM.format(
            users[telegram].get('price'), users[telegram].get('term'),
            users[telegram].get('how_much_sub'), users[telegram].get('street'),
            (int(users[telegram].get('how_much_sub')) *
             int(users[telegram].get('price'))),
            (int(product_price.get('water')) -
             int(users[telegram].get('price'))) *
            int(users[telegram].get('how_much_sub')))
    except Exception as e:
        return back_to_main_menu_del(bot, telegram)
    try:
        return reply_message(bot, telegram, message_id, text, 15)
    except Exception as e:
        print('error', e)
    return
예제 #8
0
def confirm(bot, telegram, call_id):
    pay_menu(bot, telegram)

    text = ''
    price_water = []
    print('here')
    text = FOR_SEND_ORDER_TO_OTHER_BOT2.format(telegram,
                                               users[telegram].get('name'),
                                               users[telegram].get('phone'),
                                               users[telegram].get('street'))
    if users[telegram].get('water'):
        try:
            if users[telegram].get('water'):
                insert_order(
                    **{
                        'telegram':
                        telegram,
                        'name':
                        users[telegram].get('name'),
                        'phone':
                        users[telegram].get('phone'),
                        'goods':
                        'water',
                        'amount':
                        users[telegram].get('water'),
                        'sum': (users[telegram].get('water') *
                                product_price.get('water')),
                        'street':
                        users[telegram].get('street')
                    })

                summa = users[telegram].get('water') * product_price.get(
                    'water') * 100
                price_water.append(LabeledPrice(label='water19', amount=summa))
                prices.update({
                    telegram: [
                        LabeledPrice(label='water19',
                                     amount=int(users[telegram].get('water')) *
                                     int(product_price.get('water')))
                    ]
                })
                try:
                    text += FOR_SEND_BOTTLE_TO_OTHER_BOT.format(
                        'вода', users[telegram].get('water'),
                        (users[telegram].get('water') *
                         int(product_price.get('water'))))
                except Exception as e:
                    print('error', e)
        except Exception as e:
            return back_to_main_menu_del(bot, telegram)
    if users[telegram].get('pompa'):
        insert_order(
            **{
                'telegram': telegram,
                'name': users[telegram].get('name'),
                'phone': users[telegram].get('phone'),
                'goods': 'pompa',
                'amount': users[telegram].get('pompa'),
                'sum': (users[telegram].get('pompa') *
                        product_price.get('pompa')),
                'street': users[telegram].get('street')
            })

        try:
            text += FOR_SEND_POMPA_TO_OTHER_BOT.format(
                'помпа', users[telegram].get('pompa'),
                (users[telegram].get('pompa') * product_price.get('pompa')))
            summa = int(users[telegram].get('pompa')) * int(
                product_price.get('pompa')) * 100

            price_water.append(LabeledPrice(label='pompa', amount=summa))
            if prices.get(telegram):
                prices[telegram].append(
                    LabeledPrice(label='pompa',
                                 amount=users[telegram].get('pompa') *
                                 product_price.get('pompa')))
            else:
                prices.update({
                    telegram: [
                        LabeledPrice(label='pompa',
                                     amount=int(users[telegram].get('pompa')) *
                                     int(product_price.get('pompa')))
                    ]
                })

        except Exception as e:
            print('error pompa', e)

    if users[telegram].get('pompaEL'):
        insert_order(
            **{
                'telegram':
                telegram,
                'name':
                users[telegram].get('name'),
                'phone':
                users[telegram].get('phone'),
                'goods':
                'pompaEL',
                'amount':
                users[telegram].get('pompaEL'),
                'sum': (users[telegram].get('pompaEL') *
                        product_price.get('pompaEL')),
                'street':
                users[telegram].get('street')
            })

        summa = int(users[telegram].get('pompaEL')) * int(
            product_price.get('pompaEL')) * 100
        price_water.append(LabeledPrice(label='pompaEL', amount=summa))
        if prices.get(telegram):
            prices[telegram].append(
                LabeledPrice(label='pompaEL',
                             amount=users[telegram].get('pompaEL') *
                             product_price.get('pompaEL')))
        else:
            prices.update({
                telegram: [
                    LabeledPrice(label='pompaEL',
                                 amount=int(users[telegram].get('pompaEL')) *
                                 int(product_price.get('pompaEL')))
                ]
            })

        try:
            text += FOR_SEND_POMPA_TO_OTHER_BOT.format(
                'помпа электрическа', users[telegram].get('pompaEL'),
                (users[telegram].get('pompaEL') *
                 product_price.get('pompaEL')))
        except Exception as e:
            print('error pompaEL', e)
    print('here')
    if users[telegram].get('culer'):
        insert_order(
            **{
                'telegram': telegram,
                'name': users[telegram].get('name'),
                'phone': users[telegram].get('phone'),
                'goods': 'culer',
                'amount': users[telegram].get('culer'),
                'sum': (users[telegram].get('culer') *
                        product_price.get('culer')),
                'street': users[telegram].get('street')
            })

        summa = int(users[telegram].get('culer')) * int(
            product_price.get('culer')) * 100
        price_water.append(LabeledPrice(label='culer', amount=summa))

        if prices.get(telegram):
            prices[telegram].append(
                LabeledPrice(label='culer',
                             amount=users[telegram].get('culer') *
                             product_price.get('culer')))
        else:
            prices.update({
                telegram: [
                    LabeledPrice(label='culer',
                                 amount=int(users[telegram].get('culer')) *
                                 int(product_price.get('culer')))
                ]
            })
        try:
            text += FOR_SEND_POMPA_TO_OTHER_BOT.format(
                'кулер', users[telegram].get('culer'),
                (users[telegram].get('culer') * product_price.get('culer')))
        except Exception as e:
            print('error pompa', e)
    print('here')
    users[telegram].update(report=text)
    print('here')
    report(text)
    try:
        users.pop(telegram)
    except Exception as e:
        print(e)
예제 #9
0
def confirm_menu(bot, telegram):
    try:
        text_for_confirm = DATES_FOR_CONFIRM.format(
            users[telegram].get('name'), users[telegram].get('phone'),
            users[telegram].get('street'))
    except Exception as e:
        return back_to_main_menu_del(bot, telegram)
    total = 1

    prices_productes = []

    if users[telegram].get('water'):
        text_for_confirm += BOTTLE_FOR_CONFIRM.format(
            users[telegram].get('water'), product_price.get('water'),
            (users[telegram].get('water') * int(product_price.get('water'))))
        total = users[telegram].get('water') * int(product_price.get('water'))
        prices_productes.append(
            LabeledPrice(label='water',
                         amount=int(users[telegram].get('water')) *
                         int(product_price.get('water')) * 100))
    if users[telegram].get('pompa'):
        text_for_confirm += POMPA_FOR_CONFIRM.format(
            users[telegram].get('pompa'), product_price.get('pompa'),
            (users[telegram].get('pompa') * int(product_price.get('pompa'))))
        total += users[telegram].get('pompa') * int(product_price.get('pompa'))
        prices_productes.append(
            LabeledPrice(label='pompa',
                         amount=int(users[telegram].get('pompa')) *
                         int(product_price.get('pompa')) * 100))

    if users[telegram].get('pompaEL'):
        text_for_confirm += POMPA_FOR_CONFIRM.format(
            users[telegram].get('pompaEL'), product_price.get('pompaEL'),
            (users[telegram].get('pompaEL') *
             int(product_price.get('pompaEL'))))
        total += users[telegram].get('pompaEL') * int(
            product_price.get('pompaEL'))
        prices_productes.append(
            LabeledPrice(label='pompaEL',
                         amount=int(users[telegram].get('pompaEL')) *
                         int(product_price.get('pompaEL')) * 100))

    if users[telegram].get('culer'):
        text_for_confirm += CULER_FOR_CONFIRM.format(
            users[telegram].get('culer'), product_price.get('culer'),
            (users[telegram].get('culer') * int(product_price.get('culer'))))
        total += users[telegram].get('culer') * int(product_price.get('culer'))
        prices_productes.append(
            LabeledPrice(label='culer',
                         amount=int(users[telegram].get('culer')) *
                         int(product_price.get('culer')) * 100))

    prices.update({telegram: prices_productes})
    text_for_confirm += ITOG_CONFIRM.format(total)
    # if first:

    try:
        del_menu(bot, telegram, select_menu(telegram).get('message_id'))
    except Exception as e:
        print(e)

    send_menu(bot, telegram, text_for_confirm, 8)