Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update ServerChan to Turbo version #18

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ jobs:
env:
COOKIES: ${{ secrets.SMZDM_COOKIE }}
SERVERCHAN_SECRETKEY: ${{ secrets.SERVERCHAN_SECRETKEY }}
WX_PUSHER: ${{ secrets.WX_PUSHER }}
WX_PUSHER_UID: ${{ secrets.WX_PUSHER_UID }}
run: python main.py #>SMZDM_Bot.log
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ first push

+ 2020-12-12
修复如果没有填写`SERVERCHAN_SECRETKEY`,会在正常签到后报错的问题。
现在没有`SERVERCHAN_SECRETKEY`也可以正常签到并不报错。
现在没有`SERVERCHAN_SECRETKEY`也可以正常签到并不报错。

11 changes: 6 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ def checkin(self):
sb.load_cookie_str(cookies)
res = sb.checkin()
print(res)
SERVERCHAN_SECRETKEY = os.environ["SERVERCHAN_SECRETKEY"]
print('sc_key: ', SERVERCHAN_SECRETKEY)
if isinstance(SERVERCHAN_SECRETKEY,str) and len(SERVERCHAN_SECRETKEY)>0:
print('检测到 SCKEY, 准备推送')
WX_PUSHER_UID = os.environ["WX_PUSHER_UID"]
WX_PUSHER = os.environ["WX_PUSHER"]
if isinstance(WX_PUSHER,str) and len(WX_PUSHER)>0:
print('检测到 WX_PUSHER 准备推送')
push_to_wechat(text = '什么值得买每日签到',
desp = str(res),
secretKey = SERVERCHAN_SECRETKEY)
appToken=WX_PUSHER,
uid=WX_PUSHER_UID)
print('代码完毕')
32 changes: 21 additions & 11 deletions utils/serverchan_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@
import requests


def push_to_wechat(text,desp,secretKey):
def push_to_wechat(text, desp, appToken, uid):
"""
通过serverchan将消息推送到微信
:param secretKey: severchan secretKey
:param text: 标题
:param desp: 内容
:return resp: json
通过wxpusher将消息推送到微信
"""
url = f'http://sc.ftqq.com/{secretKey}.send'
url = f'http://wxpusher.zjiecode.com/api/send/message'
session = requests.Session()
data = {'text':text,'desp':desp}
resp = session.post(url,data = data)
data = {
"appToken": appToken,
"content": desp,
"summary": text,
"contentType": 1,
"topicIds": [],
"uids": [
uid
],
}
headers = {
'Content-Type': 'application/json'
}
resp = session.post(url, json=data, headers=headers)
return resp.json()


if __name__ == '__main__':
resp = push_to_wechat(text = 'test', desp='hi', secretKey= config.SERVERCHAN_SECRETKEY)
print(resp)
resp = push_to_wechat(text='test', desp='hi',
appToken='',
uid='')
print(resp)