forked from easypickings/smzdm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (42 loc) · 1.34 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'''
什么值得买自动签到脚本
'''
import os
import requests
import config
from push import pushplus
class SMZDM_Bot(object):
def __init__(self):
self.session = requests.Session()
# 添加 headers
self.session.headers = config.DEFAULT_HEADERS
def load_cookie_str(self, cookie):
'''为session添加cookie.
Args:
cookie: 什么值得买登录cookie.
'''
self.session.headers['Cookie'] = cookie
def checkin(self):
'''签到函数.
Returns:
请求响应内容.
'''
url = 'https://zhiyou.smzdm.com/user/checkin/jsonp_checkin'
rsp = self.session.get(url)
try:
result = rsp.json()
return result
except:
return rsp.content
if __name__ == '__main__':
sb = SMZDM_Bot()
cookie = os.environ.get('COOKIE') or config.COOKIE
sb.load_cookie_str(cookie)
res = sb.checkin()
print(res)
TOKEN = os.environ.get('PUSH_PLUS_TOKEN') or config.PUSH_PLUS_TOKEN
if TOKEN:
print('检测到PUSH_PLUS_TOKEN, 准备推送')
title = '什么值得买每日签到' + ('成功' if res.get('error_code') == 0 else '失败')
pushplus(title=title, content=res, token=TOKEN)
print('代码完毕')