def start(update, context): chat = utils.get_chat(context, update) chat_id = chat.effective_chat.id user = update.message.from_user logger.info(f'start -> {chat_id}') try: if utils.is_new_user(user.id): logger.info(f'start New User: {chat_id}') db.add_user(user) update.message.reply_text( config.text['initial']) update.message.reply_text( config.text['initial_next'] ) return NAME else: update.message.reply_text( config.text['select_menu'], reply_markup=utils.get_start_kb() ) except Exception as ex: logger.warning(ex, exc_info=True) return CHOOSING_CATEGORY
def delivery_time_handler(update, context): try: logger.info(f'delivery_time_handler: {update, context}') chat = utils.get_chat(context, update) message = utils.get_message(context, update) chat_id = chat.effective_chat.id context.bot.editMessageReplyMarkup( chat_id=message.chat_id, message_id=message.message_id, reply_markup=InlineKeyboardMarkup( utils.generate_time_suggest_reply_keyb( chat_id, utils.get_delivery_time_from_callback( chat.callback_query.data) )), parse_mode=ParseMode.MARKDOWN ) context.bot.send_message( chat_id=utils.get_user_id_from_callback(chat.callback_query.data), text=f'Ваш заказ будет доставлен в течении ' f'{utils.get_delivery_time_from_callback(chat.callback_query.data)} ' f'минут', reply_markup=utils.get_ok_ko_markup() ) except Exception as ex: logger.warning(f'delivery_time_handler: {ex}')
def order_confirmation_handler(update, context): chat = utils.get_chat(context, update) chat_id = chat.effective_chat.id context.user_data.update(payment_type=update.message.text) logger.info(f'order_confirmation_handler -> {context.user_data}') update.message.reply_text( utils.generate_full_order_info(context.user_data, chat_id), parse_mode=ParseMode.MARKDOWN, reply_markup=utils.get_confirm_order_kb() )
def get_logs_handler(update, context): chat = utils.get_chat(context, update) chat_id = chat.effective_chat.id bot = utils.get_bot(context, update) logger.info(f'get_logs_handler -> {chat_id}') if utils.is_admin(chat_id): try: f = open('deliver_bot.log', 'rb') bot.send_document( chat_id=chat_id, document=f ) except Exception as ex: logger.warning(f'{ex}')
def chat_get_methods(item): data = request.get_json() if request.get_json() else {} if item == 'get-products': result = utils.get_products_forChat(data) elif item == 'get-product-chat': result = utils.get_product_chats(data) elif item == 'get-chat': result = utils.get_chat(data) else: return jsonify({ 'status': config.HTML_STATUS_CODE['NotFound'], 'message': 'Wrong url!' }) return jsonify(result)
def get_db_handler(update, context): chat = utils.get_chat(context, update) chat_id = chat.effective_chat.id bot = utils.get_bot(context, update) logger.info(f'get_db_handler -> {chat_id}') if utils.is_admin(chat_id): try: f_path = os.path.join(os.path.dirname(__file__), 'admin/db.sqlite') f = open(f_path, 'rb') bot.send_document( chat_id=chat_id, document=f ) except Exception: pass
def cart_handler(update, context): chat = utils.get_chat(context, update) chat_id = chat.effective_chat.id if 'cart' not in context.user_data: update.message.reply_text( config.text['empty_card'] ) logger.info(f'cart_handler: empty_card {chat_id}') return start(update, context) else: update.message.reply_text( utils.generate_cart_reply_text(context.user_data), parse_mode=ParseMode.MARKDOWN, reply_markup=utils.get_cart_kb(context.user_data['cart']) ) logger.info(f'card_handler: show cart items to user {chat_id}') return EDITING_CART
def get_report_handler(update, context): chat = utils.get_chat(context, update) chat_id = chat.effective_chat.id bot = utils.get_bot(context, update) logger.info(f'get_report_handler -> {chat_id}') db.export_orders_to_file() if utils.is_admin(chat_id): try: f = open('orders.csv', 'rb') bot.send_document( chat_id=chat_id, document=f ) except Exception as ex: logger.warning(f'{ex}') pass
def submit_order_handler(update, context): chat = utils.get_chat(context, update) chat_id = chat.effective_chat.id logger.info(f'submit_order_handler -> {context.user_data}') order_id = utils.add_order(context.user_data, chat_id) context.user_data.update( order_id=order_id) # 1. Send Order Info to admins chat utils.send_message_to_admin( context.bot, f'{utils.generate_full_order_info(context.user_data, chat_id)} \n\n' f'`User_id: {chat_id}` \n' f'`Order_id: {order_id}` \n', True, chat_id) # 2. Send notification to user update.message.reply_text( utils.generate_order_confirmation( context.user_data ), reply_markup=utils.get_start_kb() ) done(update, context)
'Messages Wednesday', 'Messages Thursday', 'Messages Friday', 'Messages Saturday', 'Messages Sunday', 'Total breaks', 'Total exclamations!', 'Total interrogations?', 'Total capital letters', 'Total links', 'Total videos', 'Total images', 'Total audios' ] + common_words) # Count total messages + start date + end date chats = utils.list_chats(INPUTS_PATH) for chat_name in chats: print('#' * 50) print('#' * 50) print(chat_name) print('-' * 50) chat_path = os.path.join(INPUTS_PATH, chat_name) chat = utils.get_chat(chat_path) # Decrease the time 4 hours to compensate time shift France/Brazil: chat.df['date'] -= timedelta(hours=4) print('Chat start date: ', chat.start_date) print('Chat end date: ', chat.end_date) # Remove messages from user r = chat.df[(chat.df.username == 'Giuliander Carpes')].index chat.df.drop(r) # Limit study period days_before = chat.df[(chat.df.date <= '2020-11-09')].index aux_chat = chat.df.drop(days_before) days_after = aux_chat[(aux_chat.date >= '2021-03-10')].index