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