-
Notifications
You must be signed in to change notification settings - Fork 933
/
main.py
66 lines (57 loc) · 1.91 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
什么值得买自动签到脚本
使用github actions 定时执行
@author : stark
"""
import requests,os
from sys import argv
import config
from utils.serverchan_push import push_to_wechat
class SMZDM_Bot(object):
def __init__(self):
self.session = requests.Session()
# 添加 headers
self.session.headers = config.DEFAULT_HEADERS
def __json_check(self, msg):
"""
对请求 盖乐世社区 返回的数据进行进行检查
1.判断是否 json 形式
"""
try:
result = msg.json()
print(result)
return True
except Exception as e:
print(f'Error : {e}')
return False
def load_cookie_str(self, cookies):
"""
起一个什么值得买的,带cookie的session
cookie 为浏览器复制来的字符串
:param cookie: 登录过的社区网站 cookie
"""
self.session.headers['Cookie'] = cookies
def checkin(self):
"""
签到函数
"""
url = 'https://zhiyou.smzdm.com/user/checkin/jsonp_checkin'
msg = self.session.get(url)
if self.__json_check(msg):
return msg.json()
return msg.content
if __name__ == '__main__':
sb = SMZDM_Bot()
# sb.load_cookie_str(config.TEST_COOKIE)
cookies = os.environ["COOKIES"]
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, 准备推送')
push_to_wechat(text = '什么值得买每日签到',
desp = str(res),
secretKey = SERVERCHAN_SECRETKEY)
print('代码完毕')