質問編集履歴
3
その他のファイルも追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -145,3 +145,41 @@
|
|
145
145
|
app.run()
|
146
146
|
|
147
147
|
```
|
148
|
+
|
149
|
+
```requirements.txt
|
150
|
+
|
151
|
+
certifi==2021.5.30
|
152
|
+
|
153
|
+
charset-normalizer==2.0.3
|
154
|
+
|
155
|
+
click==8.0.1
|
156
|
+
|
157
|
+
Flask==2.0.1
|
158
|
+
|
159
|
+
future==0.18.2
|
160
|
+
|
161
|
+
gunicorn==20.1.0
|
162
|
+
|
163
|
+
idna==3.2
|
164
|
+
|
165
|
+
itsdangerous==2.0.1
|
166
|
+
|
167
|
+
Jinja2==3.0.1
|
168
|
+
|
169
|
+
line-bot-sdk==1.19.0
|
170
|
+
|
171
|
+
MarkupSafe==2.0.1
|
172
|
+
|
173
|
+
requests==2.26.0
|
174
|
+
|
175
|
+
urllib3==1.26.6
|
176
|
+
|
177
|
+
Werkzeug==2.0.1
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
```procfile
|
182
|
+
|
183
|
+
web: gunicorn app:app --log-file -
|
184
|
+
|
185
|
+
```
|
2
二箇所、暗号のような部分を伏せました
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,9 +40,9 @@
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
-
line_bot_api = LineBotApi('
|
43
|
+
line_bot_api = LineBotApi('ふせさせていただきます。')
|
44
44
|
|
45
|
-
handler = WebhookHandler('
|
45
|
+
handler = WebhookHandler('ふせさせていただきます')
|
46
46
|
|
47
47
|
|
48
48
|
|
1
コードを追加しました。reply_message変数に格納している「勉強時間は{hour}時間....」の部分を「勉強時間{hour}時間....」といった風に「は」の文字を消しただけです。
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,3 +7,141 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
この方の動画を参考にしてlinebotを作り、無事に完成したのですが、自分で改良する際に、vscodeのコードを変えても変更されませんでした。どうすれば変更した部分が反映されるのでしょうか。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
```python
|
14
|
+
|
15
|
+
from flask import Flask, request, abort
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
from linebot import (
|
20
|
+
|
21
|
+
LineBotApi, WebhookHandler
|
22
|
+
|
23
|
+
)
|
24
|
+
|
25
|
+
from linebot.exceptions import (
|
26
|
+
|
27
|
+
InvalidSignatureError
|
28
|
+
|
29
|
+
)
|
30
|
+
|
31
|
+
from linebot.models import (
|
32
|
+
|
33
|
+
MessageEvent, TextMessage, TextSendMessage,
|
34
|
+
|
35
|
+
)
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
app = Flask(__name__)
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
line_bot_api = LineBotApi('fyMaA+zFTba4fkMhMpfQa+twJqw+/z/BF2XvMRS7wxMLnwOxVanmTxqEXyJo2RGuxAyJNZx2dWgy6FB4lue4XeoOv+0nwhARQf0tBDN2lSLjJHdDkAG6ykknOqICAZVPTlhLlReOvLAN1MMLj7IHpgdB04t89/1O/w1cDnyilFU=')
|
44
|
+
|
45
|
+
handler = WebhookHandler('4c2582c5fcfd8dbe6fc51c5a259035e6')
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
@app.route("/")
|
50
|
+
|
51
|
+
def test():
|
52
|
+
|
53
|
+
return "OK"
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
@app.route("/callback", methods=['POST'])
|
58
|
+
|
59
|
+
def callback():
|
60
|
+
|
61
|
+
# get X-Line-Signature header value
|
62
|
+
|
63
|
+
signature = request.headers['X-Line-Signature']
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
# get request body as text
|
68
|
+
|
69
|
+
body = request.get_data(as_text=True)
|
70
|
+
|
71
|
+
app.logger.info("Request body: " + body)
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
# handle webhook body
|
76
|
+
|
77
|
+
try:
|
78
|
+
|
79
|
+
handler.handle(body, signature)
|
80
|
+
|
81
|
+
except InvalidSignatureError:
|
82
|
+
|
83
|
+
print("Invalid signature. Please check your channel access token/channel secret.")
|
84
|
+
|
85
|
+
abort(400)
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
return 'OK'
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
from time import time
|
94
|
+
|
95
|
+
users = {}
|
96
|
+
|
97
|
+
@handler.add(MessageEvent, message=TextMessage)
|
98
|
+
|
99
|
+
def handle_message(event):
|
100
|
+
|
101
|
+
userId = event.source.user_id
|
102
|
+
|
103
|
+
if event.message.text == "勉強開始":
|
104
|
+
|
105
|
+
reply_message = "計測を開始しました。"
|
106
|
+
|
107
|
+
if not userId in users:
|
108
|
+
|
109
|
+
users[userId] = {}
|
110
|
+
|
111
|
+
users[userId]["total"] = 0
|
112
|
+
|
113
|
+
users[userId]["start"] = time()
|
114
|
+
|
115
|
+
else:
|
116
|
+
|
117
|
+
end = time()
|
118
|
+
|
119
|
+
difference = int(end - users[userId]["start"])
|
120
|
+
|
121
|
+
users[userId]["total"] += difference
|
122
|
+
|
123
|
+
hour = difference // 3600
|
124
|
+
|
125
|
+
minute = (difference % 3600) // 60
|
126
|
+
|
127
|
+
second = difference % 60
|
128
|
+
|
129
|
+
reply_message = f"勉強時間は{hour}時間{minute}分{second}秒です。お疲れ様でした!合計で{users[userId]['total']}秒勉強しています。"
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
line_bot_api.reply_message(
|
134
|
+
|
135
|
+
event.reply_token,
|
136
|
+
|
137
|
+
TextSendMessage(text=reply_message))
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
if __name__ == "__main__":
|
144
|
+
|
145
|
+
app.run()
|
146
|
+
|
147
|
+
```
|