Skip to content

Commit

Permalink
fix unfollowing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
shoda888 committed May 17, 2020
1 parent fa8a396 commit 7950559
Showing 1 changed file with 41 additions and 62 deletions.
103 changes: 41 additions & 62 deletions lambda_function.py
Expand Up @@ -13,70 +13,49 @@ def lambda_handler(event, context):
'Content-Type': 'application/json'
}
message_dist = json.loads(event["body"])

print(message_dist["events"])

if not message_dist["events"][0]["type"] == "unfollow":
# 友達登録時
if message_dist["events"][0]["type"] == "follow":
json_open = open('json/Romance.json', 'r')

# 友達登録時
if message_dist["events"][0]["type"] == "follow":
json_open = open('json/Height.json', 'r')
elif message_dist["events"][0]["type"] == "postback":
postback = message_dist["events"][0]["postback"]["data"]
postback_action = postback.split("&")[0].split("=")[1]
# DB保存用
# postback_value = postback.split("&")[1].split("=")[1]
if postback_action == "romance":
json_open = open('json/Major.json', 'r')
if postback_action == "major":
json_open = open('json/Club.json', 'r')
if postback_action == "club":
json_open = open('json/Work.json', 'r')
if postback_action == "work":
json_open = open('json/Height.json', 'r')
if postback_action == "height":
json_open = open('json/Style.json', 'r')
if postback_action == "style":
json_open = open('json/Age.json', 'r')
if postback_action == "age":
json_open = open('json/Opinion.json', 'r')
if postback_action == "opinion":
json_open = open('json/Emotion.json', 'r')
if postback_action == "emotion":
json_open = open('json/Aicode.json', 'r')

elif message_dist["events"][0]["type"] == "postback":
postback = message_dist["events"][0]["postback"]["data"]
postback_action = postback.split("&")[0].split("=")[1]
if postback_action == "height":
json_open = open('json/Style.json', 'r')
if postback_action == "style":
json_open = open('json/Age.json', 'r')
if postback_action == "age":
json_open = open('json/Subject.json', 'r')
if postback_action == "subject":
json_open = open('json/Club.json', 'r')
if postback_action == "club":
json_open = open('json/Job.json', 'r')
if postback_action == "job":
json_open = open('json/Alcohol.json', 'r')
if postback_action == "alcohol":
json_open = open('json/Smoke.json', 'r')
if postback_action == "smoke":
json_open = open('json/Fashion.json', 'r')
if postback_action == "fashion":
json_open = open('json/Social1.json', 'r')
if postback_action == "social1":
json_open = open('json/Social2.json', 'r')
if postback_action == "social2":
json_load = {
"type": "text",
"text": "回答ありがとうございました。あなたのIDは" + user_num + "です。"
}

#ユーザーがBotに何らかを送信した場合
# elif message_dist["events"][0]["type"] == "message":
# # #ユーザーの画像送信をキャッチ
# if message_dist["events"][0]["message"]["type"] == "image":
# pass
# #ユーザーのID送信をキャッチ
# if re.match(r"^[0-9]{6}", message_dist["events"][0]["message"]["text"]) :
# try :
# json_load = {
# "type": "text",
# "text": "相性は"+ matching(user_id) + "です。すごーい"
# }
# read_flag = False
# except :
# json_load = {
# "type": "text",
# "text": "相性診断に失敗しました。IDを確認してください。"
# }
# else :
# json_open = open('json/Error.json', 'r')
else:
json_open = open('json/Error.json', 'r')
else:
json_open = open('json/error.json', 'r')

params = {
"replyToken": message_dist["events"][0]["replyToken"],
"messages": [json_load]
}
request = urllib.request.Request(url, json.dumps(params).encode("utf-8"), method=method, headers=headers)
with urllib.request.urlopen(request) as res:
body = res.read()
print("入力", body)
json_load = json.load(json_open)
params = {
"replyToken": message_dist["events"][0]["replyToken"],
"messages": [json_load]
}
request = urllib.request.Request(url, json.dumps(params).encode("utf-8"), method=method, headers=headers)
with urllib.request.urlopen(request) as res:
body = res.read()
# print(body)

return 0

0 comments on commit 7950559

Please sign in to comment.