mirror of
https://github.com/hex-ci/smzdm_script.git
synced 2026-02-02 18:48:52 +08:00
Add smzdm_bot
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -127,3 +127,6 @@ dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# cookies
|
||||
cookies.json
|
||||
14
.vscode/launch.json
vendored
Normal file
14
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: Current File",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true,
|
||||
"envFile": "${workspaceFolder}/.env"
|
||||
}
|
||||
]
|
||||
}
|
||||
35
README.md
35
README.md
@@ -1,2 +1,33 @@
|
||||
# SignBot
|
||||
Sign Bot
|
||||
# 什么值得买每日签到脚本
|
||||
|
||||
<p align="center">
|
||||
<img src="https://img.shields.io/github/license/chasing66/smzdm_bot">
|
||||
<img src="https://img.shields.io/badge/python-v3.9-orange"/>
|
||||
<img src="https://img.shields.io/github/last-commit/chasing66/smzdm_bot">
|
||||
<img src="https://img.shields.io/github/languages/code-size/chasing66/smzdm_bot">
|
||||
</p>
|
||||
|
||||
## 1. 实现功能
|
||||
|
||||
- `什么值得买`每日签到
|
||||
- 通过`pushplus`推送运行结果到微信
|
||||
|
||||
## 2. 使用方法
|
||||
|
||||
1. Fork[此仓库项目](https://github.com/chasing66/smzdm_bot)>点击右上角 Fork 按钮即可, 欢迎点`star`~
|
||||
2. Secret 新增`COOKIE`, 填入[什么值得买官网](https://www.smzdm.com/)获取的 Cookie 信息, [详见](#31-cookie获取方法)
|
||||
3. (可选) Secret 新增`PUSH_PLUS_TOKEN`用于推送通知, [详见](https://www.pushplus.plus/)
|
||||
4. 设置环境变量
|
||||
|
||||
```bash
|
||||
export SMZDM_COOKIE=xxxx
|
||||
export PUSH_PLUS_TOKEN=xxxx
|
||||
```
|
||||
|
||||
## 3. 其它
|
||||
|
||||
### 3.1 Cookie 获取方法
|
||||
|
||||
- 使用 Chrome 浏览器访问[什么值得买官网](https://www.smzdm.com/), 登录账号
|
||||
- 打开开发者工具 (Windows 快捷键`F12`, MacOS 快捷键`option + command + i`)
|
||||
- 选择 Network, 刷新页面, 选择第一个`www.smzdm.com`, 找到`Requests Headers`里的`Cookie`
|
||||
|
||||
83
main.py
Normal file
83
main.py
Normal file
@@ -0,0 +1,83 @@
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pprint import pprint
|
||||
|
||||
import requests
|
||||
from notifications.pushplus import pushplus
|
||||
|
||||
|
||||
class SMZDM_Bot(object):
|
||||
|
||||
DEFAULT_HEADERS = {
|
||||
'Accept': '*/*',
|
||||
'Accept-Encoding': 'gzip, deflate, br',
|
||||
'Accept-Language': 'zh-CN,zh;q=0.9',
|
||||
'Connection': 'keep-alive',
|
||||
'Host': 'zhiyou.smzdm.com',
|
||||
'Referer': 'https://www.smzdm.com/',
|
||||
'Sec-Fetch-Dest': 'script',
|
||||
'Sec-Fetch-Mode': 'no-cors',
|
||||
'Sec-Fetch-Site': 'same-site',
|
||||
'User-Agent': ('Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
|
||||
'AppleWebKit/537.36 (KHTML, like Gecko) '
|
||||
'Chrome/74.0.3729.131 Safari/537.36'),
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
self.session = requests.Session()
|
||||
self.session.headers = self.DEFAULT_HEADERS
|
||||
|
||||
def update_cookies(self, cookies):
|
||||
self.session.cookies.update(cookies)
|
||||
|
||||
def set_cookies(self, cookies):
|
||||
self.session.headers['Cookie'] = cookies
|
||||
|
||||
def checkin(self):
|
||||
url = 'https://zhiyou.smzdm.com/user/checkin/jsonp_checkin'
|
||||
resp = self.session.get(url)
|
||||
if resp.status_code == 200:
|
||||
resp_data = resp.json()["data"]
|
||||
checkin_num = resp_data["checkin_num"]
|
||||
gold = resp_data["gold"]
|
||||
point = resp_data["point"]
|
||||
exp = resp_data["exp"]
|
||||
rank = resp_data["rank"]
|
||||
cards = resp_data["cards"]
|
||||
msg = f'''⭐签到成功{checkin_num}天
|
||||
🏅金币{gold}
|
||||
🏅积分{point}
|
||||
🏅经验{exp}
|
||||
🏅等级{rank}
|
||||
🏅补签卡{cards}'''
|
||||
return msg
|
||||
else:
|
||||
pprint("Faile to sign in")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
smzdm_bot = SMZDM_Bot()
|
||||
if not os.environ.get("SMZDM_COOKIE", None):
|
||||
current_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
cookies_file_path = os.path.join(current_dir, 'cookies.json')
|
||||
if not os.path.exists(cookies_file_path):
|
||||
pprint("Cookies not existed, exit")
|
||||
sys.exit(1)
|
||||
with open("cookies.json", "r") as f:
|
||||
cookies = json.load(f)
|
||||
smzdm_cookies = {}
|
||||
for cookie in cookies:
|
||||
smzdm_cookies.update({cookie["name"]: cookie["value"]})
|
||||
smzdm_bot.update_cookies(smzdm_cookies)
|
||||
else:
|
||||
smzdm_cookies = os.environ.get(
|
||||
"SMZDM_COOKIE").encode('UTF-8').decode('latin-1')
|
||||
smzdm_bot.set_cookies(smzdm_cookies)
|
||||
resp = smzdm_bot.checkin()
|
||||
if not os.environ.get('PUSH_PLUS_TOKEN'):
|
||||
pprint("Skip PushPlus notication")
|
||||
else:
|
||||
title = '什么值得买每日签到'
|
||||
token = os.environ.get('PUSH_PLUS_TOKEN')
|
||||
pushplus(title=title, content=resp, token=token)
|
||||
25
notifications/pushplus.py
Normal file
25
notifications/pushplus.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import json
|
||||
import requests
|
||||
import os
|
||||
|
||||
|
||||
def pushplus(title, content, token, template='html'):
|
||||
url = 'https://www.pushplus.plus/send'
|
||||
body = {
|
||||
'token': token,
|
||||
'title': title,
|
||||
'content': content,
|
||||
'template': template
|
||||
}
|
||||
data = json.dumps(body).encode(encoding='utf-8')
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
rsp = requests.post(url, data=data, headers=headers)
|
||||
return rsp.json()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
token = os.environ.get('PUSH_PLUS_TOKEN')
|
||||
res = pushplus(title='Title',
|
||||
content='Content',
|
||||
token=token)
|
||||
print(res)
|
||||
17
notifications/serverchan.py
Normal file
17
notifications/serverchan.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import requests
|
||||
import os
|
||||
|
||||
|
||||
def serverchan(text, desp, secretKey):
|
||||
url = f'http://sc.ftqq.com/{secretKey}.send'
|
||||
session = requests.Session()
|
||||
data = {'text': text, 'desp': desp}
|
||||
resp = session.post(url, data=data)
|
||||
return resp.json()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
token = os.environ.get('PUSH_PLUS_TOKEN')
|
||||
resp = serverchan(text='test', desp='hi',
|
||||
secretKey=token)
|
||||
print(resp)
|
||||
7
requirements.txt
Normal file
7
requirements.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
certifi==2022.9.24
|
||||
charset-normalizer==2.1.1
|
||||
docopt==0.6.2
|
||||
idna==3.4
|
||||
requests==2.28.1
|
||||
urllib3==1.26.12
|
||||
yarg==0.1.9
|
||||
Reference in New Issue
Block a user