1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
""" |
3
|
|
|
:author @gnodgl |
4
|
|
|
cron: 11 6 * * * |
5
|
|
|
new Env('Site'); |
6
|
|
|
""" |
7
|
|
|
|
8
|
|
|
import json |
9
|
|
|
import re |
10
|
|
|
from json.decoder import JSONDecodeError |
11
|
|
|
|
12
|
|
|
import requests |
13
|
|
|
|
14
|
|
|
from notify_mtr import send |
15
|
|
|
from utils import get_data |
16
|
|
|
|
17
|
|
|
desp = "" |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
def log(info): |
21
|
|
|
global desp |
22
|
|
|
desp = desp + info + "\n\n" |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
class Site: |
26
|
|
|
def __init__(self, check_items): |
27
|
|
|
self.check_items = check_items |
28
|
|
|
self.error_tip = "cookie 已过期或网站类型不对" |
29
|
|
|
|
30
|
|
|
@staticmethod |
31
|
|
|
def generate_headers(url): |
32
|
|
|
return { |
33
|
|
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " |
34
|
|
|
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36", |
35
|
|
|
"Accept-Language": "zh-CN,zh;q=0.9", |
36
|
|
|
"Referer": url, |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
@staticmethod |
40
|
|
|
def cookie_parse(cookie_str): |
41
|
|
|
cookie_dict = {} |
42
|
|
|
cookies = cookie_str.split(";") |
43
|
|
|
for cookie in cookies: |
44
|
|
|
cookie = cookie.split("=") |
45
|
|
|
cookie_dict[cookie[0]] = cookie[1] |
46
|
|
|
return cookie_dict |
47
|
|
|
|
48
|
|
|
def signin(self, session, url): |
49
|
|
|
# hdarea 签到 |
50
|
|
|
if url == "https://www.hdarea.co": |
51
|
|
|
self.hdarea(session, url) |
52
|
|
|
elif url == "https://pterclub.com": |
53
|
|
|
self.pterclub(session, url) |
54
|
|
|
elif url == "https://www.haidan.video": |
55
|
|
|
self.haidan(session, url) |
56
|
|
|
elif url == "https://pt.btschool.club": |
57
|
|
|
self.btschool(session, url) |
58
|
|
|
elif url == "https://lemonhd.org": |
59
|
|
|
self.lemonhd(session, url) |
60
|
|
|
elif url in ["https://hdtime.org", "https://www.pttime.org"]: |
61
|
|
|
self.hdtime(session, url) |
62
|
|
|
else: |
63
|
|
|
self.common(session, url) |
64
|
|
|
|
65
|
|
|
@staticmethod |
66
|
|
|
def signin_base(session, url, data=None, **kwargs): |
67
|
|
|
attendance_url = kwargs.get("attendance_url") |
68
|
|
|
success = kwargs.get("success", []) |
69
|
|
|
repeat = kwargs.get("repeat", []) |
70
|
|
|
failure = kwargs.get("failure", "") |
71
|
|
|
with session.get(attendance_url, data) as response: |
72
|
|
|
r1 = re.compile(success[0]) |
73
|
|
|
r2 = re.compile(repeat[0]) |
74
|
|
|
location = r1.search(response.text) |
75
|
|
|
if location: |
76
|
|
|
tip = success[1] |
77
|
|
|
elif r2.search(response.text): |
78
|
|
|
tip = repeat[1] |
79
|
|
|
else: |
80
|
|
|
tip = failure |
81
|
|
|
print(f"{url} {tip}") |
82
|
|
|
if tip == "btschool": |
83
|
|
|
tip = location.group() |
84
|
|
|
log(f"{url} {tip}") |
85
|
|
|
|
86
|
|
|
def hdarea(self, session, url): |
87
|
|
|
self.signin_base( |
88
|
|
|
session, |
89
|
|
|
url, |
90
|
|
|
attendance_url=f"{url}/sign_in.php", |
91
|
|
|
data={"action": "sign_in"}, |
92
|
|
|
success=[r"获得了\d+魔力值", "签到成功"], |
93
|
|
|
repeat=[r"重复", "重复签到"], |
94
|
|
|
failure="签到失败", |
95
|
|
|
) |
96
|
|
|
|
97
|
|
|
@staticmethod |
98
|
|
|
def pterclub(session, url): |
99
|
|
|
attendance_url = f"{url}/attendance-ajax.php" |
100
|
|
|
with session.get(attendance_url) as response: |
101
|
|
|
try: |
102
|
|
|
msg = json.loads( |
103
|
|
|
response.text.encode("utf-8").decode("unicode-escape") |
104
|
|
|
).get("message") |
105
|
|
|
except JSONDecodeError: |
106
|
|
|
msg = response.text |
107
|
|
|
if "连续签到" in msg: |
108
|
|
|
pattern = re.compile(r"</?.>") |
109
|
|
|
tip = f"签到成功, {re.sub(pattern, '', msg)}" |
110
|
|
|
elif "重复刷新" in msg: |
111
|
|
|
tip = "重复签到" |
112
|
|
|
else: |
113
|
|
|
tip = "签到失败" |
114
|
|
|
print(f"{url} {tip}") |
115
|
|
|
log(f"{url} {tip}") |
116
|
|
|
|
117
|
|
|
def haidan(self, session, url): |
118
|
|
|
self.signin_base( |
119
|
|
|
session, |
120
|
|
|
url, |
121
|
|
|
attendance_url=f"{url}/signin.php", |
122
|
|
|
success=[r"已经打卡", "签到成功"], |
123
|
|
|
repeat=[r"退出", "重复签到"], |
124
|
|
|
failure="cookie 已过期或网站类型不对!", |
125
|
|
|
) |
126
|
|
|
|
127
|
|
|
def btschool(self, session, url): |
128
|
|
|
self.signin_base( |
129
|
|
|
session, |
130
|
|
|
url, |
131
|
|
|
attendance_url=f"{url}/index.php?action=addbonus", |
132
|
|
|
success=[r"今天签到您获得\d+点魔力值", "btschool"], |
133
|
|
|
repeat=[r"退出", "重复签到"], |
134
|
|
|
failure="cookie 已过期", |
135
|
|
|
) |
136
|
|
|
|
137
|
|
|
def lemonhd(self, session, url): |
138
|
|
|
self.signin_base( |
139
|
|
|
session, |
140
|
|
|
url, |
141
|
|
|
attendance_url=f"{url}/attendance.php", |
142
|
|
|
success=[r"已签到", "签到成功"], |
143
|
|
|
repeat=[r"请勿重复刷新", "重复签到"], |
144
|
|
|
failure="签到失败", |
145
|
|
|
) |
146
|
|
|
|
147
|
|
|
def hdtime(self, session, url): |
148
|
|
|
self.signin_base( |
149
|
|
|
session, |
150
|
|
|
url, |
151
|
|
|
attendance_url=f"{url}/attendance.php", |
152
|
|
|
success=[r"签到成功", "签到成功"], |
153
|
|
|
repeat=[r"请勿重复刷新", "重复签到"], |
154
|
|
|
failure="cookie 已过期", |
155
|
|
|
) |
156
|
|
|
|
157
|
|
|
@staticmethod |
158
|
|
|
def common(session, url): |
159
|
|
|
attendance_url = f"{url}/attendance.php" |
160
|
|
|
with session.get(attendance_url) as response: |
161
|
|
|
r = re.compile(r"请勿重复刷新") |
162
|
|
|
r1 = re.compile(r"签到已得\s*\d+") |
163
|
|
|
location = r1.search(response.text).span() |
164
|
|
|
if r.search(response.text): |
165
|
|
|
tip = "重复签到" |
166
|
|
|
elif location: |
167
|
|
|
tip = response.text[location[0], location[1]] |
168
|
|
|
else: |
169
|
|
|
tip = "cookie 已过期" |
170
|
|
|
print(f"{url} {tip}") |
171
|
|
|
log(f"{url} {tip}") |
172
|
|
|
|
173
|
|
|
@staticmethod |
174
|
|
|
def signin_discuz_dsu(session, url): |
175
|
|
|
attendance_url = ( |
176
|
|
|
f"{url}/plugin.php?" |
177
|
|
|
f"id=dsu_paulsign:sign&operation=qiandao&infloat=1&sign_as=1&inajax=1" |
178
|
|
|
) |
179
|
|
|
hash_url = f"{url}/plugin.php?id=dsu_paulsign:sign" |
180
|
|
|
with session.get(hash_url) as hashurl: |
181
|
|
|
h = re.compile(r'name="formhash" value="(.*?)"') |
182
|
|
|
formhash = h.search(hashurl.text)[1] |
183
|
|
|
data = { |
184
|
|
|
"qdmode": 3, |
185
|
|
|
"qdxq": "kx", |
186
|
|
|
"fastreply": 0, |
187
|
|
|
"formhash": formhash, |
188
|
|
|
"todaysay": "", |
189
|
|
|
} |
190
|
|
|
with session.post(attendance_url, data) as response: |
191
|
|
|
r = re.compile(r"签到成功") |
192
|
|
|
r1 = re.compile(r"已经签到") |
193
|
|
|
if r.search(response.text): |
194
|
|
|
log(f"{url} 签到成功") |
195
|
|
|
elif r1.search(response.text): |
196
|
|
|
log(f"{url} 重复签到") |
197
|
|
|
else: |
198
|
|
|
log(f"{url} {response.text}") |
199
|
|
|
print(f"{url} {response.text}") |
200
|
|
|
|
201
|
|
|
@staticmethod |
202
|
|
|
def signin_hifi(session, url): |
203
|
|
|
attendance_url = f"{url}/sg_sign.htm" |
204
|
|
|
with session.post(attendance_url) as response: |
205
|
|
|
r = re.compile(r"成功") |
206
|
|
|
r1 = re.compile(r"今天已经") |
207
|
|
|
if r.search(response.text): |
208
|
|
|
log(f"{url} 签到成功") |
209
|
|
|
elif r1.search(response.text): |
210
|
|
|
log(f"{url} 重复签到") |
211
|
|
|
else: |
212
|
|
|
log(f"{url} {response.text}") |
213
|
|
|
print(f"{url} {response.text}") |
214
|
|
|
|
215
|
|
|
def main(self): |
216
|
|
|
for check_item in self.check_items: |
217
|
|
|
s = requests.session() |
218
|
|
|
url = check_item.get("url") |
219
|
|
|
site_type = check_item.get("type") |
220
|
|
|
cookie = self.cookie_parse(check_item.get("cookie")) |
221
|
|
|
header = self.generate_headers(url) |
222
|
|
|
s.headers.update(header) |
223
|
|
|
s.cookies.update(cookie) |
224
|
|
|
if site_type == "pt": |
225
|
|
|
self.signin(s, url) |
226
|
|
|
elif site_type == "discuz": |
227
|
|
|
self.signin_discuz_dsu(s, url) |
228
|
|
|
elif site_type == "hifi": |
229
|
|
|
self.signin_hifi(s, url) |
230
|
|
|
else: |
231
|
|
|
log("请在配置文件中配置网站类型,如 type: 'pt'") |
232
|
|
|
print("请在配置文件中配置网站类型,如 type: 'pt'") |
233
|
|
|
return desp |
234
|
|
|
|
235
|
|
|
|
236
|
|
|
if __name__ == "__main__": |
237
|
|
|
_data = get_data() |
238
|
|
|
_check_items = _data.get("SITE", []) |
239
|
|
|
result = Site(check_items=_check_items).main() |
240
|
|
|
send("Site", result) |
241
|
|
|
|