-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendToLine.py
58 lines (46 loc) · 1.66 KB
/
sendToLine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# (1)必要なパッケージをインポート
from linebot import LineBotApi
from linebot.models import TextSendMessage,FileMessage
from linebot.exceptions import LineBotApiError
import csv
from info import getChannelSecret
# (2)LINE APIへ接続するための定数を定義。
LINE_CHANNEL_SECRET= getChannelSecret()
# LINE APIを定義。引数にアクセストークンを与える。
line_bot_api = LineBotApi(LINE_CHANNEL_SECRET)
def sendToLine(fromName,title,body,hasAttachments):
with open('uid.csv') as fp:
reader = csv.reader(fp)
header = next(reader)
ulst = []
for row in reader:
ulst.append(row[0])
print(ulst)
with open('gid.csv') as fp:
reader = csv.reader(fp)
header = next(reader)
glst = []
for row in reader:
glst.append(row[0])
print(glst)
message = "from:" + fromName + "\n" + "title:" + title + "\n\n" + body
if hasAttachments:
message = message + "\n\n" + "※添付ファイルあり"
try:
# ラインユーザIDは配列で指定する。
line_bot_api.multicast(
ulst, TextSendMessage(text=message)
)
for groupId in glst:
line_bot_api.push_message(
groupId, TextSendMessage(text=message)
)
except LineBotApiError as e:
# エラーが起こり送信できなかった場合
print(e)
if __name__ == '__main__':
testFrom = "川上 昌汰"
testTitle = "テスト"
testBody = "テストメールでございます。"
hasAttachments = True
sendToLine(testFrom,testTitle,testBody,hasAttachments)