forked from limoruirui/misaka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_msg.py
46 lines (44 loc) · 1.72 KB
/
send_msg.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
#!/usr/bin/python3
# -- coding: utf-8 --
# -------------------------------
# @Author : github@limoruirui https://github.com/limoruirui
# @Time : 2022/8/23 23:31
# -------------------------------
from requests import post
from json import dumps
from sys import path
path.append("./tools")
from tool import get_environ
tg_userId = get_environ("TG_USER_ID", "", False)
tgbot_token = get_environ("TG_BOT_TOKEN_ADDED", "", False) if get_environ("TG_BOT_TOKEN_ADDED", "", False) else get_environ("TG_BOT_TOKEN", "", False)
tg_push_api = get_environ("TG_API_HOST", "", False)
pushplus_token = get_environ("PUSH_PLUS_TOKEN_ADDED", "", False) if get_environ("PUSH_PLUS_TOKEN_ADDED", "", False) else get_environ("PUSH_PLUS_TOKEN", "", False)
def tgpush(title, content):
url = f"https://api.telegram.org/bot{tgbot_token}/sendMessage"
if tg_push_api != "":
url = f"https://{tg_push_api}/bot{tgbot_token}/sendMessage"
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = {'chat_id': str(tg_userId), 'text': f"{title}\n{content}", 'disable_web_page_preview': 'true'}
try:
post(url, headers=headers, data=data, timeout=10)
except:
print('推送失败')
def pushplus(title, content):
url = "http://www.pushplus.plus/send"
headers = {
"Content-Type": "application/json"
}
data = {
"token": pushplus_token,
"title": title,
"content": content
}
try:
post(url, headers=headers, data=dumps(data))
except:
print('推送失败')
def push(title, content):
if pushplus_token != "" and pushplus_token != "no":
pushplus(title, content)
if tgbot_token != "" and tgbot_token != "no" and tg_userId != "":
tgpush(title, content)