def after_preference3(event=None, line_bot_api=None): user_id = event.source.user_id postback = getattr(event, "postback", None) if postback is not None: _food_sports = postback.data.split("&")[1] repo.update_users(user_id, "food_sports", _food_sports) _is_food_main = _get_food_main(user_id) if _is_food_main: _text = "オススメの食事を送るね♪\n朝食は何時に送る?" Session_interface.set_waiting_mode(user_id, MODE.AFTER_PREFERENCE4) line_bot_api.push_message(user_id, TextSendMessage(text=_text, quick_reply=QuickReply( items=[ QuickReplyButton(action=DatetimePickerAction( label="時間を選んでね!", data=MODE.AFTER_PREFERENCE4.hash, mode="time", initial="", min="00:00", max="23:59" )) ] ))) else: Session_interface.set_waiting_mode(user_id, MODE.LAST) last(event=event, line_bot_api=line_bot_api)
def after_preference1(event=None, line_bot_api=None): user_id = event.source.user_id postback = getattr(event, "postback", None) if postback is not None: _is_sports = postback.data.split("&")[1] repo.update_users(user_id, "is_sports", _is_sports) if _is_sports == "はい": is_sports = True else: is_sports = False _text = "オッケー!" line_bot_api.reply_message(event.reply_token, TextSendMessage(text=_text)) dur() if is_sports: _text = "いつもどこで運動するの?" Session_interface.set_waiting_mode(user_id, MODE.AFTER_PREFERENCE2) line_bot_api.push_message(user_id, TextSendMessage(text=_text, quick_reply=QuickReply( items=[ QuickReplyButton(action=PostbackAction(label="自宅で", data=MODE.AFTER_PREFERENCE2.hash+"&自宅で", text="自宅で")), QuickReplyButton(action=PostbackAction(label="ジムで", data=MODE.AFTER_PREFERENCE2.hash+"&ジムで", text="ジムで")), QuickReplyButton(action=PostbackAction(label="それ以外で", data=MODE.AFTER_PREFERENCE2.hash+"&それ以外", text="それ以外")) ] ))) else: Session_interface.set_waiting_mode(user_id, MODE.AFTER_PREFERENCE2) after_preference2(event=event, line_bot_api=line_bot_api)
def after_goal_date(event=None, line_bot_api=None): user_id = event.source.user_id postback = getattr(event, "postback", None) if postback is not None: _goal_date = postback.params["date"] repo.update_users(user_id, "goal_date", _goal_date) _goal_dt = _get_goal_date(user_id) _goal_weight = _get_goal_weight(user_id) _delta_date = _goal_dt - dt.now() _delta_weight = _get_weight(user_id) - _goal_weight _text = "{delta_date}日で{delta_weight}キロが目標なんですね!".format( delta_date=_delta_date.days, delta_weight=_delta_weight) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=_text)) dur() print(2222, _delta_date.days, _delta_weight, _goal_weight, _goal_date) if int(10*_delta_weight/(_delta_date.days+0.000001*30))/10.0 < THRESHOLD_WEIGHT: _text = "一緒に頑張っていきましょう!" Session_interface.set_waiting_mode(user_id, MODE.AFTER_VALID_GOAL) line_bot_api.push_message(user_id, TextSendMessage(text=_text)) after_valid_goal(event=event, line_bot_api=line_bot_api) else: _text = "目標がハードすぎます。最高でも30日5キロまでにしてください" line_bot_api.push_message(user_id, TextSendMessage(text=_text)) _text = "改めて、目標体重を入力してね" Session_interface.set_waiting_mode(user_id, MODE.AFTER_GOAL_WEIGHT) line_bot_api.push_message(user_id, TextSendMessage(text=_text))
def after_purpose(event=None, line_bot_api=None): user_id = event.source.user_id postback = getattr(event, "postback", None) if postback is not None: _purpose = postback.data.split("&")[1] repo.update_users(user_id, "purpose", _purpose) _purpose=_get_purpose(user_id) _text = "そうなんですね。{}んですね。".format(_purpose) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=_text)) dur() _text = "良いアドバイスができるようにがんばります!" line_bot_api.push_message(user_id, TextSendMessage(text=_text)) dur() _text = "これからあなたに合ったアドバイスができるように、もうちょっとあなたのことを教えてくださいね" line_bot_api.push_message(user_id, TextSendMessage(text=_text)) dur() _text = "普段運動はしますか?" Session_interface.set_waiting_mode(user_id, MODE.AFTER_PREFERENCE1) line_bot_api.push_message(user_id, TextSendMessage(text=_text, quick_reply=QuickReply( items=[ QuickReplyButton(action=PostbackAction(label="はい", data=MODE.AFTER_PREFERENCE1.hash+"&はい", text="はい")), QuickReplyButton(action=PostbackAction(label="いいえ", data=MODE.AFTER_PREFERENCE1.hash+"&いいえ", text="いいえ")) ] )))
def after_email(event=None, line_bot_api=None): user_id = event.source.user_id _email = event.message.text repo.update_users(user_id, "email", _email) _text = "ありがとう!次は名字(姓)を入力してね" Session_interface.set_waiting_mode(user_id, MODE.AFTER_SIR_NAME) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=_text))
def after_height(event=None, line_bot_api=None): user_id = event.source.user_id _height = event.message.text repo.update_users(user_id, "height", _height) _text = "体重は何kgですか?\nもちろん、わたしとあなただけの秘密です^^" Session_interface.set_waiting_mode(user_id, MODE.AFTER_WEIGHT) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=_text))
def after_first_name(event=None, line_bot_api=None): user_id = event.source.user_id _first_name = event.message.text repo.update_users(user_id, "first_name", _first_name) _text = "電話番号を数字で入れてね☆ハイフンはいらないよ" Session_interface.set_waiting_mode(user_id, MODE.AFTER_PHONE) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=_text))
def after_sir_name(event=None, line_bot_api=None): user_id = event.source.user_id _sir_name = event.message.text repo.update_users(user_id, "sir_name", _sir_name) _text = "下の名前(名)をお願い!" Session_interface.set_waiting_mode(user_id, MODE.AFTER_FIRST_NAME) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=_text))
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 after_birthdate(event=None, line_bot_api=None): user_id = event.source.user_id postback = getattr(event, "postback", None) if postback is not None: _birth_date = postback.params["date"] repo.update_users(user_id, "birth_date", _birth_date) _text = "ここから少しキーボードを使って入力してください。\n左下のキーボードアイコンから開いてください♪" line_bot_api.reply_message(event.reply_token, TextSendMessage(text=_text)) dur() _text = "まずはユーザー登録をお願いします。" line_bot_api.push_message(user_id, TextSendMessage(text=_text)) dur() _text = "最初はメールアドレスを教えてね♪" Session_interface.set_waiting_mode(user_id, MODE.AFTER_EMAIL) line_bot_api.push_message(user_id, TextSendMessage(text=_text))
def after_preference2(event=None, line_bot_api=None): user_id = event.source.user_id postback = getattr(event, "postback", None) if postback is not None: _place_sports = postback.data.split("&")[1] repo.update_users(user_id, "place_sports", _place_sports) _text = "それじゃあ、どうやって目標を達成しようか?" _h = MODE.AFTER_PREFERENCE3.hash Session_interface.set_waiting_mode(user_id, MODE.AFTER_PREFERENCE3) line_bot_api.push_message(user_id, TextSendMessage(text=_text, quick_reply=QuickReply( items=[ QuickReplyButton(action=PostbackAction(label="食事中心", data=_h+"&食事中心", text="食事中心")), QuickReplyButton(action=PostbackAction(label="運動中心", data=_h+"&運動中心", text="運動中心")), QuickReplyButton(action=PostbackAction(label="どっちも", data=_h+"&どっちも", text="どっちも")) ] )))
def after_weight(event=None, line_bot_api=None): user_id = event.source.user_id _weight = event.message.text repo.update_users(user_id, "weight", _weight) repo.insert_weight_into_weight_table(user_id, _weight) _text = "教えてくれて、ありがとうございます!" line_bot_api.reply_message(event.reply_token, TextSendMessage(text=_text)) # TODO: _height, _weightをデータベースから取得する関数を実装する dur() _weight, _height = _get_weight(user_id), _get_height(user_id) _bmi = _get_bmi(_height, _weight) _text = "今の情報からすると…BMIは{}ですね".format(_bmi) line_bot_api.push_message(user_id, TextSendMessage(text=_text)) dur() _text = "目標体重は何キロですか?" Session_interface.set_waiting_mode(user_id, MODE.AFTER_GOAL_WEIGHT) line_bot_api.push_message(user_id, TextSendMessage(text=_text))
def after_goal_weight(event=None, line_bot_api=None): user_id = event.source.user_id _goal_weight = event.message.text repo.update_users(user_id, "goal_weight", _goal_weight) _text = "いつまでに目標を達成したいですか?" Session_interface.set_waiting_mode(user_id=user_id, mode=MODE.AFTER_GOAL_DATE) line_bot_api.push_message(user_id, TextSendMessage(text=_text, quick_reply=QuickReply( items=[ QuickReplyButton(action=DatetimePickerAction( label="日付を選んでね!", data=MODE.AFTER_GOAL_DATE.hash, mode="date", initial=dt.now().strftime("%Y-%m-%d"), min="2018-10-01", max="2018-12-31" )) ] )))
from datetime import datetime as dt from datetime import timedelta as delta import numpy as np 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)
for user_id in user_id_list: print(user_id) _send_customer(user_id) if __name__ == "__main__": DB_PATH = './sqlite.db' repo.create_table(DB_PATH) import random user_id = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' if not user_id in serv.get_user_id_list(): repo.insert_into_users_sex(user_id, "男性", registered_date=dt(2018, 10, 9)) registered_date = serv.get_registered_date(user_id) repo.update_users(user_id, "birth_date", "1988-01-01") repo.update_users(user_id, "email", "*****@*****.**") repo.update_users(user_id, "phone", "01232345192") repo.update_users(user_id, "sir_name", "アルバ") repo.update_users(user_id, "first_name", "アル子") repo.update_users(user_id, "height", "171") repo.update_users(user_id, "weight", "80") repo.update_users(user_id, "goal_weight", "75") repo.update_users(user_id, "goal_date", (registered_date + delta(days=60)).strftime("%Y-%m-%d")) starting_point()