def generate_random(update, context): # TODO: как-то по умному сделать штоле try: if not context.user_data['gender']: logger.info('user data not updated, trying to update...') update_user_data(update, context, session) logger.info('updated user data!') except Exception as e: logger.info('user context not initialized. updating user data...') update_user_data(update, context, session) logger.info('updated user data!') excuse_context = random.choice([ 'family', 'personal', 'health', 'leisure', 'work', 'study', 'official' ]) for i in range(MAX_RETRY): try: text = test_constructor(words=df, morph=morph, context=excuse_context, subj_sex=context.user_data['gender'], tense=context.user_data['tense']) logger.info('generated text') update.message.reply_text(text, reply_markup=keyboard) except: logger.warning('failed to generate text') continue else: break return ConversationHandler.END
def generate_crazy(update, context): for i in range(MAX_RETRY): try: text = test_constructor(words=df, morph=morph) logger.info('generated text') update.message.reply_text(text, reply_markup=fun_keyboard) except: logger.warning('failed to generate text') continue else: break return IN_FUN
def generate_not_serious(update, context): for i in range(MAX_RETRY): try: text = test_constructor(words=df, morph=morph, max_seriousness=3, subj_sex=context.user_data['gender'], tense=context.user_data['tense']) logger.info('generated text') update.message.reply_text(text, reply_markup=keyboard) except: logger.warning('failed to generate text') continue else: break
def generate_leisure(update, context): for i in range(MAX_RETRY): try: text = test_constructor(words=df, morph=morph, context='leisure', subj_sex=context.user_data['gender'], tense=context.user_data['tense']) logger.info('generated text') update.message.reply_text(text, reply_markup=context_keyboard) except: logger.warning('failed to generate text') continue else: break return IN_CONTEXTS