-
Notifications
You must be signed in to change notification settings - Fork 0
/
linenotify.py
60 lines (51 loc) · 1.61 KB
/
linenotify.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
59
60
import requests
class LineNotifyClient():
baseUrl = "https://notify-api.line.me/api/"
headers = {
"Authorization": "Bearer <TOKEN>",
"Content-Type": "application/x-www-form-urlencoded"
}
def __init__(self, token=None):
self.headers["Authorization"] = f"Bearer {token}"
def setToken(self, token):
self.headers["Authorization"] = f"Bearer {token}"
def sendNotify(
self,
message,
imageThumbnail=None,
imageFullsize=None,
notificationDisabled=False
):
data = {
"message": message,
"imageThumbnail": imageThumbnail,
"imageFullsize": imageFullsize,
"notificationDisabled": notificationDisabled
}
resp = requests.post(
self.baseUrl + "notify",
headers=self.headers,
data=data
)
if resp.status_code in [401, 400]:
return Exception('Notify token error')
return resp.json()
def checkToken(self):
resp = requests.get(
self.baseUrl + "status",
headers=self.headers
)
if resp.status_code in [401, 400]:
return Exception('Notify token error')
return resp.json()
def revokeToken(self):
resp = requests.post(
self.baseUrl + "revoke",
headers=self.headers
)
if resp.status_code in [401]:
return Exception('Notify token error')
return resp.json()
if __name__ == "__main__":
cl = LineNotifyClient("TOKEN")
print(cl.sendNotify('TEST', notificationDisabled=True))