1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
""" |
3
|
|
|
cron: 3 0 * * * |
4
|
|
|
new Env('一加手机社区官方论坛'); |
5
|
|
|
""" |
6
|
|
|
|
7
|
|
|
import re |
8
|
|
|
import time |
9
|
|
|
from urllib import parse |
10
|
|
|
|
11
|
|
|
import requests |
12
|
|
|
|
13
|
|
|
from notify_mtr import send |
14
|
|
|
from utils import get_data |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class OnePlusBBS: |
18
|
|
|
def __init__(self, check_items): |
19
|
|
|
self.check_items = check_items |
20
|
|
|
|
21
|
|
|
@staticmethod |
22
|
|
|
def sign(cookie): |
23
|
|
|
headers = { |
24
|
|
|
"Origin": "https://www.oneplusbbs.com", |
25
|
|
|
"Content-Type": "application/x-www-form-urlencoded", |
26
|
|
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " |
27
|
|
|
"AppleWebKit/537.36 (KHTML, like Gecko) " |
28
|
|
|
"Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.57", |
29
|
|
|
"Accept": "text/html,application/xhtml+xml,application/xml;" |
30
|
|
|
"q=0.9,image/webp,image/apng,*/*;" |
31
|
|
|
"q=0.8,application/signed-exchange;v=b3;q=0.9", |
32
|
|
|
"Referer": "https://www.oneplusbbs.com/plugin-dsu_paulsign:sign.html", |
33
|
|
|
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,fr;q=0.5,pl;q=0.4", |
34
|
|
|
"cookie": cookie, |
35
|
|
|
} |
36
|
|
|
params = ( |
37
|
|
|
("id", "dsu_paulsign:sign"), |
38
|
|
|
("operation", "qiandao"), |
39
|
|
|
("infloat", "1"), |
40
|
|
|
("inajax", "1"), |
41
|
|
|
) |
42
|
|
|
formhash = re.findall(r"bbs_formhash=(.*?);", cookie)[0] |
43
|
|
|
data = {"formhash": formhash, "qdxq": "kx", "qdmode": "1", "todaysay": "努力奋斗"} |
44
|
|
|
res = requests.post( |
45
|
|
|
"https://www.oneplusbbs.com/plugin.php", |
46
|
|
|
data, |
47
|
|
|
params=params, |
48
|
|
|
headers=headers, |
49
|
|
|
).text |
50
|
|
|
msg = re.findall(r'<div class="c">(.*?)</div>', res, re.S) |
51
|
|
|
msg = msg[0].strip() if msg else "Cookie 可能过期" |
52
|
|
|
return msg |
53
|
|
|
|
54
|
|
|
@staticmethod |
55
|
|
|
def draw(cookie): |
56
|
|
|
headers = { |
57
|
|
|
"Accept": "application/json, text/javascript, */*; q=0.01", |
58
|
|
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " |
59
|
|
|
"AppleWebKit/537.36 (KHTML, like Gecko) " |
60
|
|
|
"Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.57", |
61
|
|
|
"X-Requested-With": "XMLHttpRequest", |
62
|
|
|
"Origin": "https://www.oneplusbbs.com", |
63
|
|
|
"Referer": "https://www.oneplusbbs.com/plugin-choujiang.html", |
64
|
|
|
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,fr;q=0.5,pl;q=0.4", |
65
|
|
|
"cookie": cookie, |
66
|
|
|
} |
67
|
|
|
params = (("id", "choujiang"), ("do", "draw")) |
68
|
|
|
sum_list = [] |
69
|
|
|
success_count = 0 |
70
|
|
|
for i in range(10): |
71
|
|
|
try: |
72
|
|
|
res = requests.post( |
73
|
|
|
"https://www.oneplusbbs.com/plugin.php", |
74
|
|
|
params=params, |
75
|
|
|
headers=headers, |
76
|
|
|
).json() |
77
|
|
|
if res["ret"] != "": |
78
|
|
|
ret = res["ret"] |
79
|
|
|
ret_map = {"2": 18, "4": 188, "5": 88, "7": 8} |
80
|
|
|
sum_list.append(ret_map.get(ret, 0)) |
81
|
|
|
one_msg = res["msg"] |
82
|
|
|
if str(ret) in {"-1", "-6", "-7"}: |
83
|
|
|
break |
84
|
|
|
success_count += 1 |
85
|
|
|
else: |
86
|
|
|
one_msg = "抽奖失败" |
87
|
|
|
except Exception as e: |
88
|
|
|
one_msg = f"抽奖失败: {e}" |
89
|
|
|
print(f"第 {i + 1} 次抽奖结果:{str(one_msg)}") |
90
|
|
|
time.sleep(5) |
91
|
|
|
msg = f"成功抽奖 {success_count} 次" |
92
|
|
|
draw_msg = f"抽奖状态: {str(msg)}" |
93
|
|
|
draw_msg += f"\n抽奖结果: 获得 {sum(sum_list) - success_count * 10} 加油" |
94
|
|
|
print(draw_msg) |
95
|
|
|
return draw_msg |
96
|
|
|
|
97
|
|
|
def main(self): |
98
|
|
|
msg_all = "" |
99
|
|
|
for check_item in self.check_items: |
100
|
|
|
cookie = check_item.get("cookie") |
101
|
|
|
bbs_uname = re.findall(r"bbs_uname=(.*?);", cookie) |
102
|
|
|
bbs_uname = bbs_uname[0].split("%7C")[0] if bbs_uname else "未获取到用户信息" |
103
|
|
|
try: |
104
|
|
|
bbs_uname = parse.unquote(bbs_uname) |
105
|
|
|
except Exception as e: |
106
|
|
|
print(f"bbs_uname 转换失败: {e}") |
107
|
|
|
sign_msg = self.sign(cookie) |
108
|
|
|
draw_msg = self.draw(cookie) |
109
|
|
|
msg = f"帐号信息: {bbs_uname}\n签到信息: {sign_msg}\n{draw_msg}" |
110
|
|
|
msg_all += msg + "\n\n" |
111
|
|
|
return msg_all |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
if __name__ == "__main__": |
115
|
|
|
_data = get_data() |
116
|
|
|
_check_items = _data.get("ONEPLUSBBS", []) |
117
|
|
|
result = OnePlusBBS(check_items=_check_items).main() |
118
|
|
|
send("一加手机社区官方论坛", result) |
119
|
|
|
|