├── .github
└── workflows
│ └── main.yml
├── README.md
├── config.py
├── main.py
├── pics
└── log_20201212.jpg
├── requirements.txt
└── utils
├── __init__.py
└── serverchan_push.py
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | # This is a basic workflow to help you get started with Actions
2 |
3 | name: "GitHub Actions SMZDM Bot"
4 |
5 | # Controls when the action will run. Triggers the workflow on push or pull request
6 | # events but only for the main branch
7 | on:
8 | push:
9 | # branches: [ main ]
10 | pull_request:
11 | branches: [ main ]
12 | schedule:
13 | - cron: '0 23 * * *'
14 |
15 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
16 | jobs:
17 | # This workflow contains a single job called "build"
18 | build:
19 | # The type of runner that the job will run on
20 | runs-on: ubuntu-latest
21 |
22 | # Steps represent a sequence of tasks that will be executed as part of the job
23 | steps:
24 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
25 | - uses: actions/checkout@v2
26 |
27 | - name: Set up Python
28 | uses: actions/setup-python@v1
29 | with:
30 | python-version: 3.7
31 |
32 | # Runs a set of commands using the runners shell
33 | - name: Install requirements
34 | run: |
35 | pip install -r requirements.txt
36 |
37 | - name: Working
38 | env:
39 | COOKIES: ${{ secrets.SMZDM_COOKIE }}
40 | SERVERCHAN_SECRETKEY: ${{ secrets.SERVERCHAN_SECRETKEY }}
41 | run: python main.py #>SMZDM_Bot.log
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 什么值得买每日签到脚本
2 | ===
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | # 1. 实现功能
12 | + `什么值得买`每日签到
13 | + 通过 `SERVERCHAN`推送简单的运行结果到微信
14 | + 由 `github actions` 每日7点定时运行
15 |
16 | # 2. 使用方法
17 | 1. Fork [此仓库项目](https://github.com/stark666/smzdm_bot) > 点击右上角fork按钮即可,欢迎点`star`~
18 | 2. Secret新增`SMZDM_COOKIE`,填入浏览器调试模式从[什么值得买官网](https://www.smzdm.com/)cookie信息, 不懂可看下面的其它
19 | 3. (可选)Secret新增`SERVERCHAN_SECRETKEY`,获取方法可看这篇文章[@ruicky教程](https://ruicky.me/2020/06/05/jd-sign/)
20 | 4. fork后必须修改一下文件,才能执行定时任务, 可修改 `README.MD`, 添加一个空格
21 |
22 |
23 | # 3. 其它
24 | ## 3.1 cookie获取方法
25 | + 首先使用chrome浏览器,访问[什么值得买官网](https://www.smzdm.com/), 登陆账号
26 | + Windows系统可按 `F12` 快捷键打开开发者工具, Mac 快捷键 `option + command + i`
27 | + 选择开发者工具Network,刷新页面 ,选择第一个`www.smzdm.com`, 找到`Requests Headers`里的`Cookie`。
28 |
29 | ## 3.2 更改执行时间
30 | 在 `.github/main.yml`中,找到
31 | ```yml
32 | - cron: '0 0 * * *'
33 | ```
34 | 语法同crontab,具体可百度,为美区时间,加8小时为中国时间
35 |
36 |
37 | # N. Log
38 | 在没有更换`SMZDM_COOKIE`的情况下,截至2020-12-12, 我的账号已正常签到68天,具体`SMZDM_COOKIE`有效时间继续验证。
39 | 
40 |
41 | + 2020-10-08
42 | first push
43 |
44 | + 2020-12-12
45 | 修复如果没有填写`SERVERCHAN_SECRETKEY`,会在正常签到后报错的问题。
46 | 现在没有`SERVERCHAN_SECRETKEY`也可以正常签到并不报错。
--------------------------------------------------------------------------------
/config.py:
--------------------------------------------------------------------------------
1 | """
2 | 请求头
3 | """
4 | DEFAULT_HEADERS = {
5 | 'Accept': '*/*',
6 | 'Accept-Encoding': 'gzip, deflate, br',
7 | 'Accept-Language': 'zh-CN,zh;q=0.9',
8 | 'Connection': 'keep-alive',
9 | 'Host': 'zhiyou.smzdm.com',
10 | 'Referer': 'https://www.smzdm.com/',
11 | 'Sec-Fetch-Dest': 'script',
12 | 'Sec-Fetch-Mode': 'no-cors',
13 | 'Sec-Fetch-Site': 'same-site',
14 | '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',
15 | }
16 |
17 |
18 | """
19 | 调试用 COOKIE
20 | """
21 | TEST_COOKIE = ''
22 |
23 |
24 | """
25 | 调试用 SERVERCHAN_SECRETKEY
26 | """
27 | SERVERCHAN_SECRETKEY = ''
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | """
2 | 什么值得买自动签到脚本
3 | 使用github actions 定时执行
4 | @author : stark
5 | """
6 | import requests,os
7 | from sys import argv
8 |
9 | import config
10 | from utils.serverchan_push import push_to_wechat
11 |
12 | class SMZDM_Bot(object):
13 | def __init__(self):
14 | self.session = requests.Session()
15 | # 添加 headers
16 | self.session.headers = config.DEFAULT_HEADERS
17 |
18 | def __json_check(self, msg):
19 | """
20 | 对请求 盖乐世社区 返回的数据进行进行检查
21 | 1.判断是否 json 形式
22 | """
23 | try:
24 | result = msg.json()
25 | print(result)
26 | return True
27 | except Exception as e:
28 | print(f'Error : {e}')
29 | return False
30 |
31 | def load_cookie_str(self, cookies):
32 | """
33 | 起一个什么值得买的,带cookie的session
34 | cookie 为浏览器复制来的字符串
35 | :param cookie: 登录过的社区网站 cookie
36 | """
37 | self.session.headers['Cookie'] = cookies
38 |
39 | def checkin(self):
40 | """
41 | 签到函数
42 | """
43 | url = 'https://zhiyou.smzdm.com/user/checkin/jsonp_checkin'
44 | msg = self.session.get(url)
45 | if self.__json_check(msg):
46 | return msg.json()
47 | return msg.content
48 |
49 |
50 |
51 |
52 | if __name__ == '__main__':
53 | sb = SMZDM_Bot()
54 | # sb.load_cookie_str(config.TEST_COOKIE)
55 | cookies = os.environ["COOKIES"]
56 | sb.load_cookie_str(cookies)
57 | res = sb.checkin()
58 | print(res)
59 | SERVERCHAN_SECRETKEY = os.environ["SERVERCHAN_SECRETKEY"]
60 | print('sc_key: ', SERVERCHAN_SECRETKEY)
61 | if isinstance(SERVERCHAN_SECRETKEY,str) and len(SERVERCHAN_SECRETKEY)>0:
62 | print('检测到 SCKEY, 准备推送')
63 | push_to_wechat(text = '什么值得买每日签到',
64 | desp = str(res),
65 | secretKey = SERVERCHAN_SECRETKEY)
66 | print('代码完毕')
--------------------------------------------------------------------------------
/pics/log_20201212.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stark666/smzdm_bot/a3de4c9e9fbad7521878b1fe3334c9710187f0e5/pics/log_20201212.jpg
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | requests
--------------------------------------------------------------------------------
/utils/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stark666/smzdm_bot/a3de4c9e9fbad7521878b1fe3334c9710187f0e5/utils/__init__.py
--------------------------------------------------------------------------------
/utils/serverchan_push.py:
--------------------------------------------------------------------------------
1 |
2 | import config
3 | import requests
4 |
5 |
6 | def push_to_wechat(text,desp,secretKey):
7 | """
8 | 通过serverchan将消息推送到微信
9 | :param secretKey: severchan secretKey
10 | :param text: 标题
11 | :param desp: 内容
12 | :return resp: json
13 | """
14 | url = f'http://sc.ftqq.com/{secretKey}.send'
15 | session = requests.Session()
16 | data = {'text':text,'desp':desp}
17 | resp = session.post(url,data = data)
18 | return resp.json()
19 |
20 |
21 | if __name__ == '__main__':
22 | resp = push_to_wechat(text = 'test', desp='hi', secretKey= config.SERVERCHAN_SECRETKEY)
23 | print(resp)
--------------------------------------------------------------------------------