Example #1
0
def feed_order(q, b, chat_id, mass_o, adding_time):
    creds_n = ServiceAccountCredentials.from_json_keyfile_name(
        'client_secret.json', ['https://www.googleapis.com/auth/drive'])
    client_n = gspread.authorize(creds_n)

    customers_n = client_n.open('Diploma').worksheet("Customers")
    feed_n = client_n.open('Diploma').worksheet("Feed")

    # getting line of order
    pos = Ga.get_all_new(
        [mass_o[0], mass_o[1], mass_o[2], mass_o[3], mass_o[4]], Ga.feed,
        feed_num_of_filters)[3]

    cur_am = feed_n.cell(pos + 1, 5).value
    cur_res = feed_n.cell(pos + 1, 7).value
    if cur_res == '':
        cur_res = 0

    feed_n.update_cell(pos + 1, 5, int(cur_am) - int(mass_o[4]))
    feed_n.update_cell(pos + 1, 7, int(cur_res) + int(mass_o[4]))

    id_list = customers_n.col_values(1)
    msg_id = 0

    for i in range(len(id_list)):
        if id_list[i] == str(chat_id):
            msg_id = customers_n.cell(i + 1, 5).value

            customers_n.insert_row([
                '', '', '', '', '', '', '', adding_time, mass_o[0], mass_o[1],
                mass_o[2], mass_o[3], mass_o[4],
                int(mass_o[5]) * int(mass_o[4])
            ], i + 2)

    b.deleteMessage(chat_id=q['message']['chat']['id'],
                    message_id=q['message']['message_id'])

    b.send_message(chat_id=q['message']['chat']['id'],
                   text='Thanks, your order is being processed!',
                   reply_markup=InlineKeyboardMarkup([[
                       InlineKeyboardButton('New order',
                                            callback_data='New order')
                   ]]))

    b.send_message(chat_id=341219282,
                   text='===New order===\n' + 'Pet: ' + mass_o[0] + '\n' +
                   'Type: ' + mass_o[1] + '\n' + 'Producer: ' + mass_o[2] +
                   '\n' + 'Weight: ' + mass_o[3] + '\n' + 'Amount: ' +
                   mass_o[4] + '\n' + 'Price: ' +
                   str(int(mass_o[5]) * int(mass_o[4])) + '\n' + 'Chat_id: ' +
                   str(chat_id))

    b.forward_message(chat_id=341219282,
                      from_chat_id=chat_id,
                      message_id=msg_id)

    Ga.feed = client_n.open('Diploma').worksheet("Feed").get_all_values()
Example #2
0
def feed(q, d, b, chat_id, mass_o, adding_time):
    if d == "feed":
        Kb_func.ty = 0
        Kb_func.fd = 1
        Kb_func.forward(q, d, b, Ga.feed, feed_num_of_filters, order_feed,
                        dict_list, 0)

    elif d in Ga.f_pet and Kb_func.fd == 1:
        Kb_func.forward(q, d, b, Ga.feed, feed_num_of_filters, order_feed,
                        dict_list, 1)

    elif d in Ga.f_type and Kb_func.fd == 1:
        Kb_func.forward(q, d, b, Ga.feed, feed_num_of_filters, order_feed,
                        dict_list, 2)

    elif d in Ga.f_producer and Kb_func.fd == 1:
        Kb_func.forward(q, d, b, Ga.feed, feed_num_of_filters, order_feed,
                        dict_list, 3)

    elif d in Ga.f_weight and Kb_func.fd == 1:
        Kb_func.forward(q, d, b, Ga.feed, feed_num_of_filters, order_feed,
                        dict_list, 4)

    elif d in [str(x)
               for x in range(1,
                              Ga.get_max(Ga.feed, 4) + 1)] and Kb_func.fd == 1:
        Kb_func.forward(q, d, b, Ga.feed, feed_num_of_filters, order_feed,
                        dict_list, 5, 'add_feed', 'f_6')

    elif d == 'add_feed' and Kb_func.fd == 1:
        feed_order(q, b, chat_id, mass_o, adding_time)
        Kb_func.fd = 0

    elif d == 'f_1':
        Kb_func.back(q, b, Ga.feed, feed_num_of_filters, order_feed, dict_list,
                     -1)

    elif d == 'f_2':
        Kb_func.back(q, b, Ga.feed, feed_num_of_filters, order_feed, dict_list,
                     0)

    elif d == 'f_3':
        Kb_func.back(q, b, Ga.feed, feed_num_of_filters, order_feed, dict_list,
                     1)

    elif d == 'f_4':
        Kb_func.back(q, b, Ga.feed, feed_num_of_filters, order_feed, dict_list,
                     2)

    elif d == 'f_5':
        Kb_func.back(q, b, Ga.feed, feed_num_of_filters, order_feed, dict_list,
                     3)

    elif d == 'f_6':
        Kb_func.back(q, b, Ga.feed, feed_num_of_filters, order_feed, dict_list,
                     4)
Example #3
0
def toys(q, d, b, chat_id, mass_o, adding_time):
    if d == "toys":
        Kb_func.ty = 1
        Kb_func.fd = 0
        Kb_func.forward(q, d, b, Ga.toys, toys_num_of_filters, order_toys,
                        dict_list, 0)

    elif d in Ga.t_pet and Kb_func.ty == 1:
        Kb_func.forward(q, d, b, Ga.toys, toys_num_of_filters, order_toys,
                        dict_list, 1)

    elif d in Ga.t_type and Kb_func.ty == 1:
        Kb_func.forward(q, d, b, Ga.toys, toys_num_of_filters, order_toys,
                        dict_list, 2)

    elif d in Ga.t_producer and Kb_func.ty == 1:
        Kb_func.forward(q, d, b, Ga.toys, toys_num_of_filters, order_toys,
                        dict_list, 3)

    elif d in Ga.t_size and Kb_func.ty == 1:
        Kb_func.forward(q, d, b, Ga.toys, toys_num_of_filters, order_toys,
                        dict_list, 4)

    elif d in [str(x)
               for x in range(1,
                              Ga.get_max(Ga.toys, 4) + 1)] and Kb_func.ty == 1:
        Kb_func.forward(q, d, b, Ga.toys, toys_num_of_filters, order_toys,
                        dict_list, 5, 'add_toys', 't_6')

    elif d == 'add_toys' and Kb_func.ty == 1:
        toys_order(q, b, chat_id, mass_o, adding_time)
        Kb_func.ty = 0

    elif d == 't_1':
        Kb_func.back(q, b, Ga.toys, toys_num_of_filters, order_toys, dict_list,
                     -1)

    elif d == 't_2':
        Kb_func.back(q, b, Ga.toys, toys_num_of_filters, order_toys, dict_list,
                     0)

    elif d == 't_3':
        Kb_func.back(q, b, Ga.toys, toys_num_of_filters, order_toys, dict_list,
                     1)

    elif d == 't_4':
        Kb_func.back(q, b, Ga.toys, toys_num_of_filters, order_toys, dict_list,
                     2)

    elif d == 't_5':
        Kb_func.back(q, b, Ga.toys, toys_num_of_filters, order_toys, dict_list,
                     3)

    elif d == 't_6':
        Kb_func.back(q, b, Ga.toys, toys_num_of_filters, order_toys, dict_list,
                     4)
Example #4
0
def back(q, b, mass, num_of_fil, dict_my, list_my, num):

    temp = []
    for j in dict_my.values():
        temp.append(j)

    x = [temp[i] for i in range(num)]

    if num == -1:
        q.edit_message_text(text='Choose a category:',
                            reply_markup=Ga.category())

    elif -1 < num < num_of_fil - 1:
        q.edit_message_text(text=list_my[num],
                            reply_markup=Ga.get_all_new(x, mass,
                                                        num_of_fil)[1])

    else:
        b.deleteMessage(chat_id=q['message']['chat']['id'],
                        message_id=q['message']['message_id'])
        b.send_message(chat_id=q['message']['chat']['id'],
                       text=list_my[num],
                       reply_markup=Ga.get_all_new(x, mass, num_of_fil)[1])
Example #5
0
def forward(q, d, b, mass, num_of_fil, dict_my, list_my, num, tp='', pp=''):

    temp = []
    for j in dict_my.values():
        temp.append(j)

    x = [temp[i] for i in range(num - 1)]
    x.append(d)

    # first()
    if num == 0:
        x.pop()

    if num != num_of_fil:
        q.edit_message_text(text=list_my[num],
                            reply_markup=Ga.get_all_new(x, mass,
                                                        num_of_fil)[1])

    # обновление массива  order_feed
    if num != 0:
        dict_my[num - 1] = d

    if num == num_of_fil:
        b.deleteMessage(chat_id=q['message']['chat']['id'],
                        message_id=q['message']['message_id'])

        b.send_photo(chat_id=q['message']['chat']['id'],
                     photo=Ga.get_all_new(x, mass, num_of_fil)[1],
                     caption=Ga.get_all_new(x, mass, num_of_fil)[0],
                     reply_markup=InlineKeyboardMarkup([[
                         InlineKeyboardButton('🛒', callback_data=tp),
                         InlineKeyboardButton('⬅', callback_data=pp)
                     ]]))

        dict_my[num - 1] = d
        dict_my[num] = Ga.get_all_new(x, mass, num_of_fil)[2]
Example #6
0
def do_start(bot: Bot, update: Update, optional='no'):
    global promo_code

    scope_n = ['https://www.googleapis.com/auth/drive']
    creds_n = ServiceAccountCredentials.from_json_keyfile_name(
        'client_secret.json', scope_n)
    client_n = gspread.authorize(creds_n)

    customers_n = client_n.open('Diploma').sheet1

    new_customer(customers_n,
                 chat_id=update['message']['chat']['id'],
                 name=update['message']['chat']['first_name'],
                 second_name=update['message']['chat']['last_name'],
                 username=update['message']['chat']['username'],
                 adding_time=time.asctime())

    chat_id = update['message']['chat']['id']
    msg_id = update['message']['message_id']

    id_list = customers_n.col_values(1)

    for i in range(len(id_list)):
        if id_list[i] == str(chat_id):
            customers_n.update_cell(i + 1, 5, msg_id)

    if optional == promo_code:
        for j in range(len(id_list)):
            if id_list[j] == str(chat_id):
                if customers_n.cell(j + 1, 15).value != promo_code:
                    bot.send_message(chat_id=chat_id,
                                     text='Promo code activated!')
                    customers_n.update_cell(j + 1, 15, optional)
                else:
                    bot.send_message(
                        chat_id=chat_id,
                        text='This promo code has already been activated!')

    bot.send_message(chat_id=chat_id,
                     text="Choose a category:",
                     reply_markup=Ga.category())