diff --git a/python/send.py b/python/send.py index a2edd74f25018b8da6351f2231f53c48bc8aa287..2bc3ee22daa90ab3798202137cfb3b8a523dfa15 100644 --- a/python/send.py +++ b/python/send.py @@ -1,14 +1,29 @@ import os -import urllib.parse -import urllib.request +# import urllib.parse +# import urllib.request +import requests + + +# def sc_send(text, desp='', key='[SENDKEY]'): +# postdata = urllib.parse.urlencode({'text': text, 'desp': desp}).encode('utf-8') +# url = f'https://sctapi.ftqq.com/{key}.send' +# req = urllib.request.Request(url, data=postdata, method='POST') +# with urllib.request.urlopen(req) as response: +# result = response.read().decode('utf-8') +# return result + + +def push_deer(title, massege, key='[SENDKEY]'): + url = f'https://sctapi.ftqq.com/{key}.send?' + params = { + 'title': title, + 'desp': massege, + 'channel': '18' + } + + resp = requests.post(url, params=params) + return resp.text -def sc_send(text, desp='', key='[SENDKEY]'): - postdata = urllib.parse.urlencode({'text': text, 'desp': desp}).encode('utf-8') - url = f'https://sctapi.ftqq.com/{key}.send' - req = urllib.request.Request(url, data=postdata, method='POST') - with urllib.request.urlopen(req) as response: - result = response.read().decode('utf-8') - return result data = {} with open(os.path.join(os.path.dirname(__file__), '..', '.env'), 'r') as f: @@ -17,5 +32,7 @@ with open(os.path.join(os.path.dirname(__file__), '..', '.env'), 'r') as f: data[key] = value key = data['SENDKEY'] -ret = sc_send('主人服务器宕机了', '第一行\n\n第二行', key) -print(ret) \ No newline at end of file +# ret = sc_send('主人服务器宕机了', '第一行\n\n第二行', key) +# print(ret) + +print(push_deer('主人服务器宕机了', "测试测试", key)) \ No newline at end of file