def after_preference4(event=None, line_bot_api=None): user_id = event.source.user_id postback = getattr(event, "postback", None) if postback is not None: _recom_time_morning = postback.params["time"] repo.update_users(user_id, "recom_time_morning", _recom_time_morning) print(repo.select_from_users(user_id, "recom_time_morning")) _text = "コンビニで買えるダイエットメニューを送るね!" Session_interface.set_waiting_mode(user_id, MODE.LAST) line_bot_api.push_message(user_id, TextSendMessage(text=_text)) last(event=event, line_bot_api=line_bot_api)
def recommend_training(user_id, slot=None): from line_botr import line_bot as lb goal_weight = repository.select_from_users(user_id, 'goal_weight') if slot is not None: diff_weight = int(slot) - int(goal_weight) if(diff_weight < 0): lb.push_message(user_id, '達成おめでとう!さようなら!') return lb.push_message(user_id, '今日のレコメンドはこちらの3つ!') dur() items = create_carousel('workout') template = template_env.get_template('training_with_img.json') data = template.render(dict(items=items)) lb.push_carousel_message(user_id, data) dur() lb.push_message(user_id, '朝に運動をするとで、一日の代謝量が上がるから試してみてね。') dur() if slot is not None: lb.push_message(user_id, '目標の体重まで後{}Kg, 頑張れ!'.format(diff_weight))
def _get_food_main(user_id): ret = repo.select_from_users(user_id, "food_sports") if ret in ["食事中心", "どっちも"]: return True else: False
def _get_purpose(user_id): return repo.select_from_users(user_id, "purpose")
def _get_goal_date(user_id): ret = repo.select_from_users(user_id, "goal_date") return dt.strptime(ret, "%Y-%m-%d")
def _get_goal_weight(user_id): return repo.select_from_users(user_id, "goal_weight") return 50
def _get_height(user_id): return repo.select_from_users(user_id, "height")
if __name__ == "__main__": DB_PATH = './sqlite.db' repo.create_table(DB_PATH) import random user_id = "test_user_id_in_send_customer1234567890"+str(random.randint(0,1000000)) # repo.delete_from_users(user_id) # serv.delete_weight_table(user_id) repo.insert_into_users_sex(user_id, "女性", registered_date=dt(2018,7,1)) registered_date = serv.get_registered_date(user_id) repo.update_users(user_id, "weight", "80") repo.update_users(user_id, "birth_date", "1988-01-01") repo.update_users(user_id, "goal_weight", "75") repo.update_users(user_id, "goal_date", (registered_date+delta(days=60)).strftime("%Y-%m-%d")) print("---test user table: ",repo.select_from_users(user_id, "weight")) print("----test weight table----") # 理想の体重変化を計算する sex = serv.get_sex(user_id) age = serv.get_age(user_id) goal_date = serv.get_goal_date(user_id) goal_days = (goal_date- registered_date).days goal_weight = serv.get_goal_weight(user_id) first_weight = serv.get_first_weight(user_id) N = 15 # serv.get_elapsed_days(user_id) ideal_E_in = get_E_in_by_M0_N(sex, age, goal_delta=goal_days, Mf=goal_weight, M0=first_weight) ideal_w = get_ideal_series_with_E_in(sex, age, first_weight, N, ideal_E_in) ####################################