From ce31dda507962a1ba2f4bda10ba8831cbed4ed49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E8=80=81=E5=86=9C?= Date: Mon, 17 Jul 2023 06:21:20 +0000 Subject: [PATCH 1/2] =?UTF-8?q?update=20python/send.py.=20=E7=94=A8request?= =?UTF-8?q?s=E5=BA=93=E5=8F=AF=E4=BB=A5=E8=BF=99=E6=A0=B7=E6=94=B9?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 吴老农 --- python/send.py | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/python/send.py b/python/send.py index a2edd74..b02caeb 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(massege, key='[SENDKEY]'): + url = f'https://sctapi.ftqq.com/{key}.send?' + params = { + '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 -- Gitee From 604f912b493f5deec0dcbe2d73d5f533a5924000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E8=80=81=E5=86=9C?= Date: Mon, 17 Jul 2023 06:22:48 +0000 Subject: [PATCH 2/2] update python/send.py. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 吴老农 --- python/send.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/send.py b/python/send.py index b02caeb..2bc3ee2 100644 --- a/python/send.py +++ b/python/send.py @@ -13,10 +13,10 @@ import requests # return result -def push_deer(massege, key='[SENDKEY]'): +def push_deer(title, massege, key='[SENDKEY]'): url = f'https://sctapi.ftqq.com/{key}.send?' params = { - 'title': '主人服务器宕机了', + 'title': title, 'desp': massege, 'channel': '18' } @@ -35,4 +35,4 @@ key = data['SENDKEY'] # ret = sc_send('主人服务器宕机了', '第一行\n\n第二行', key) # print(ret) -print(push_deer("测试测试", key)) \ No newline at end of file +print(push_deer('主人服务器宕机了', "测试测试", key)) \ No newline at end of file -- Gitee