質問編集履歴
4
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,10 +18,10 @@
|
|
18
18
|
import re
|
19
19
|
|
20
20
|
headers = {
|
21
|
-
'X-ChatWorkToken': '
|
21
|
+
'X-ChatWorkToken': 'xxxxxxxxxxxxxxxxxx',
|
22
22
|
}
|
23
23
|
|
24
|
-
response = requests.get('https://api.chatwork.com/v2/rooms/
|
24
|
+
response = requests.get('https://api.chatwork.com/v2/rooms/xxxxxxx/messages?force=1', headers=headers)
|
25
25
|
print(response.status_code)
|
26
26
|
|
27
27
|
if response.status_code==200:
|
3
文法の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -25,8 +25,11 @@
|
|
25
25
|
print(response.status_code)
|
26
26
|
|
27
27
|
if response.status_code==200:
|
28
|
-
|
28
|
+
messages = response.json()
|
29
|
-
with open('
|
29
|
+
with open('chat.log','a') as f:
|
30
|
-
re.findall('[info].*[/info]', 'chat_log.json')
|
31
|
-
|
30
|
+
for message in messages:
|
31
|
+
body = message['body']
|
32
|
+
for info in re.findall(r"[info]([\S\s]+)[/info]", body):
|
32
|
-
|
33
|
+
f.write(info.key + '\n')
|
34
|
+
message.encode('cp932')
|
35
|
+
message.encode('cp932', "ignore")
|
2
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -26,22 +26,6 @@
|
|
26
26
|
|
27
27
|
if response.status_code==200:
|
28
28
|
data = response.json()
|
29
|
-
with open(re.findall('<info>.*</info>', 'chat_log.json'),'a') as f:
|
30
|
-
for i, dic in enumerate(data):
|
31
|
-
f.write(dic['body'] + '\n')import requests
|
32
|
-
import json
|
33
|
-
import re
|
34
|
-
|
35
|
-
headers = {
|
36
|
-
'X-ChatWorkToken': 'b0a4cbfe093f9ef0ae56d0b400ec1232',
|
37
|
-
}
|
38
|
-
|
39
|
-
#cURLのオプション設定 {roomId}の箇所には取得したルームIDを入れる
|
40
|
-
response = requests.get('https://api.chatwork.com/v2/rooms/213313301/messages?force=1', headers=headers)
|
41
|
-
print(response.status_code)
|
42
|
-
|
43
|
-
if response.status_code==200:
|
44
|
-
data = response.json()
|
45
29
|
with open('chat_log.json','a') as f:
|
46
30
|
re.findall('[info].*[/info]', 'chat_log.json')
|
47
31
|
for i, dic in enumerate(data):
|
1
修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
【python】チャットワークから
|
1
|
+
【python】チャットワークから[info]で囲まれたメッセージを取得したい
|
body
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
|
-
チャットワークにて
|
2
|
+
チャットワークにて[info][/info]で囲まれたメッセージを
|
3
3
|
データとして収集したいのですが、
|
4
4
|
下記ERRORがでてしまいます。
|
5
5
|
|
@@ -28,4 +28,21 @@
|
|
28
28
|
data = response.json()
|
29
29
|
with open(re.findall('<info>.*</info>', 'chat_log.json'),'a') as f:
|
30
30
|
for i, dic in enumerate(data):
|
31
|
+
f.write(dic['body'] + '\n')import requests
|
32
|
+
import json
|
33
|
+
import re
|
34
|
+
|
35
|
+
headers = {
|
36
|
+
'X-ChatWorkToken': 'b0a4cbfe093f9ef0ae56d0b400ec1232',
|
37
|
+
}
|
38
|
+
|
39
|
+
#cURLのオプション設定 {roomId}の箇所には取得したルームIDを入れる
|
40
|
+
response = requests.get('https://api.chatwork.com/v2/rooms/213313301/messages?force=1', headers=headers)
|
41
|
+
print(response.status_code)
|
42
|
+
|
43
|
+
if response.status_code==200:
|
44
|
+
data = response.json()
|
45
|
+
with open('chat_log.json','a') as f:
|
46
|
+
re.findall('[info].*[/info]', 'chat_log.json')
|
47
|
+
for i, dic in enumerate(data):
|
31
48
|
f.write(dic['body'] + '\n')
|