forked from jeremyephron/simplegmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
line_notify.py
28 lines (25 loc) · 869 Bytes
/
line_notify.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
# -*- coding: utf-8 -*-
import requests,os
from dotenv import load_dotenv
# 環境変数を参照
load_dotenv()
LINE_API_TOKEN = os.getenv('LINE_API_TOKEN')
#------画像を送る場合----------------------------
def line_push(message, img_path=None):
url = "https://notify-api.line.me/api/notify"
token = LINE_API_TOKEN
headers = {"Authorization" : "Bearer "+ token}
payload = {"message" : message}
#imagesフォルダの中のgazo.jpg
if not img_path:
r = requests.post(url ,headers = headers ,params=payload)
else:
files = {"imageFile":open(img_path,'rb')}
post = requests.post(url ,headers = headers ,params=payload,files=files)
if __name__ == '__main__':
import sys
message = sys.argv[1]
if 2 < len(sys.argv):
line_push(message, img_path=sys.argv[2])
else:
line_push(message)