def send_notification(bot): notification_not_send = db.get_not_send_notifications() notification_count = 0 for notification in notification_not_send: delivery_number = str(notification[3]) order_number = str(notification[1]) notify = notification[4] user_id = str(notification[2]) user = db.get_user_byid(user_id) if not notify: if user[6] == 1: db.set_notifications_sended(delivery_number) bot.send_message(user_id, "Ваш заказ отправлен.\n" "Номер вашего заказа: " + order_number + '\n' "Номер вашей накладной: " + delivery_number) elif user[6] == 2: db.set_notifications_sended(delivery_number) bot.send_message(user_id, "Ваше замовлення відправлено.\n" "Номер вашого замовлення " + order_number + "\n" "Номер вашої накладної: " + delivery_number) notification_count = notification_count + 1 return notification_count
def make_basket_record(user_id): # get user user = db.get_user_byid(user_id) # get basket basket = db.get_basket_by_userid(user_id) # use creds to create a client to interact with the Google Drive API scope = ['https://spreadsheets.google.com/feeds'] creds = ServiceAccountCredentials.from_json_keyfile_name('config/client_secret.json', scope) client = gspread.authorize(creds) # Find a workbook by key and open the first sheet sheet = client.open_by_key(ORDER_KEY).sheet1 now = datetime.datetime.now() date = str(now.date()) + '.' + str(now.month) + '.' + str(now.year) + ' ' + str(now.hour) + ':' + str(now.minute) user_name = user[2] telegram_username = user[7] user_telephone = user[3] order_number = basket[6] order_list = calculate_order(user_id) order_list_final = '' for a in order_list: order_list_final = order_list_final + a + 'шт., ' comments = basket[3] payment_metode = basket[5] delivery_adress = user[5] delivery_date = basket[4] total_price = basket[2] data = [date, user_id, user_name, telegram_username, user_telephone, order_number, order_list_final, comments, payment_metode, delivery_adress, delivery_date, total_price] sheet.append_row(data)
def make_basket(message): user_id = message.from_user.id user = db.get_user_byid(user_id) lng = user[6] orders = calculate_order(user_id) if orders: if lng == 1: result = 'У вас в корзине: \n' elif lng == 2: result = 'У вашому кошику: \n' for order in orders: result = result + order + ' шт.' '\n' return result if not orders: return None
def add_cover_to_basket(message): user_id = message.from_user.id user = db.get_user_byid(user_id) cover_price = 30 if user[6] == 1: cover = 'в подарочной упаковке; ' elif user[6] == 2: cover = 'в святковій обкладинці; ' # db.add_cover_to_basket(user_id) basket = db.get_basket_by_userid(user_id) basket_order = basket[1] basket_order = basket_order[0:-2] basket_order = basket_order + ' ' + cover db.add_order_to_basket(user_id, basket_order) basket_price = basket[2] basket_price = basket_price + cover_price db.add_price_to_basket(user_id, basket_price)
def get_user_data_unaccepted(message): user_id = message.from_user.id user_data = db.get_user_data_by_userid_unaccepted(user_id) user = db.get_user_byid(user_id) lng = user[6] if user_data: if lng == 1: result = 'Полное имя: ' + user_data[0] + '\n' + \ 'Номер телефона: ' + user_data[1] + '\n' + \ 'Email: ' + user_data[2] + '\n' + \ 'Адрес доставки: ' + user_data[3] + '\n' return result elif lng == 2: result = 'Повне ім\'я:' + user_data[0] + '\n' + \ 'Номер телефону: ' + user_data[1] + '\n' + \ 'Email: ' + user_data[2] + '\n' + \ 'Адреса доставки: ' + user_data[3] + '\n' return result else: return None
def get_user(message): user_id = message.from_user.id user = db.get_user_byid(user_id) if not user: add_user(message) return user