-
Notifications
You must be signed in to change notification settings - Fork 3
/
ck_v2ex.py
94 lines (84 loc) · 3.25 KB
/
ck_v2ex.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
"""
cron: 10 8 * * *
new Env('V2EX');
"""
import re
import requests
import urllib3
from sendNotify import send
from utils import get_data
urllib3.disable_warnings()
class V2ex:
def __init__(self, check_items):
self.check_items = check_items
self.url = "https://www.v2ex.com/mission/daily"
def sign(self, session):
msg = ""
response = session.get(url=self.url, verify=False)
pattern = (
r"<input type=\"button\" class=\"super normal button\""
r" value=\".*?\" onclick=\"location\.href = \'(.*?)\';\" />"
)
urls = re.findall(pattern=pattern, string=response.text)
url = urls[0] if urls else None
if url is None:
return "cookie 可能过期"
elif url != "/balance":
data = {"once": url.split("=")[-1]}
_ = session.get(
url="https://www.v2ex.com" + url.split("?")[0],
verify=False,
params=data,
)
response = session.get(url="https://www.v2ex.com/balance", verify=False)
total = re.findall(
pattern=r"<td class=\"d\" style=\"text-align: right;\">(\d+\.\d+)</td>",
string=response.text,
)
total = total[0] if total else "签到失败"
today = re.findall(
pattern=r'<td class="d"><span class="gray">(.*?)</span></td>',
string=response.text,
)
today = today[0] if today else "签到失败"
username = re.findall(
pattern=r"<a href=\"/member/.*?\" class=\"top\">(.*?)</a>",
string=response.text,
)
username = username[0] if username else "用户名获取失败"
msg += f"帐号信息: {username}\n今日签到: {today}\n帐号余额: {total}"
response = session.get(url=self.url, verify=False)
data = re.findall(
pattern=r"<div class=\"cell\">(.*?)天</div>", string=response.text
)
data = data[0] + "天" if data else "获取连续签到天数失败"
msg += f"\n签到天数: {data}"
msg = msg.strip()
return msg
def main(self):
msg_all = ""
for check_item in self.check_items:
cookie = {
item.split("=")[0]: item.split("=")[1]
for item in check_item.get("cookie").split("; ")
}
session = requests.session()
requests.utils.add_dict_to_cookiejar(session.cookies, cookie)
session.headers.update(
{
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36",
"referer": self.url,
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
}
)
msg = self.sign(session=session)
msg_all += msg + "\n\n"
print(msg_all)
return msg_all
if __name__ == "__main__":
data = get_data()
_check_items = data.get("V2EX", [])
res = V2ex(check_items=_check_items).main()
send("V2EX", res)