-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
109 lines (94 loc) · 3.79 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import json
import os
from urllib.parse import quote
import httpx
"""
百变小樱自动签到
@auther Admsec
"""
class AutoBBxySign:
def __init__(self):
self.headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, "
"like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0"}
self.session = httpx.Client()
self.originUrl = ""
self.loginUrl = ""
self.email = os.environ.get("email")
self.password = os.environ.get("password")
self.plusplusToken = os.environ.get("token")
self.params = {"email": self.email, "passwd": self.password, "remember-me": '0'}
self.signSuccessOrNot = False
self.signSuccessMsg = ""
'''
检查每个网站
'''
def check_websites_sync(self, websites):
with httpx.Client(headers=self.headers) as client:
for site in websites:
try:
response = client.get(site)
if response.status_code == 200:
print(f"这个链接可用,就你了: {site}")
self.loginUrl = site + "auth/login"
self.originUrl = site
return site
except httpx.RequestError as e:
print(f"这个链接不能用,避一避: {site} - {e}")
# 在这里可以加入针对失败访问的站点的后续操作
continue # 尝试下一个站点
'''
登录
'''
def login(self):
r = self.session.post(url=self.loginUrl, params=self.params, headers=self.headers)
# print(r.text)
response = json.loads(r.text)
if response['ret'] != 1:
print(f"登录失败, 原因:{response['msg']}")
return False
print("登录成功")
return True
"""
签到
"""
def sign(self):
client = self.session.post(url=self.originUrl + "user/checkin", params=self.params, headers=self.headers)
print(client.text)
response = json.loads(client.text)
if response['ret'] != 1:
print(f"签到失败了,原因是{response['msg']}")
self.signSuccessMsg = response['msg']
return False
self.signSuccessMsg = response
self.signSuccessOrNot = True
return True
"""
消息模板,顺便发送消息到微信公众号
"""
def msgTemplate(self):
if self.signSuccessOrNot:
msg = (f"签到成功\n总流量{self.signSuccessMsg['traffic']}\n"
f"今日已用{self.signSuccessMsg['trafficInfo'].get('todayUsedTraffic')}\n"
f"总共已用{self.signSuccessMsg['trafficInfo'].get('lastUsedTraffic')}\n"
f"剩余流量{self.signSuccessMsg['trafficInfo'].get('unUsedTraffic')}\n")
print(msg)
plusplusUrl = f"http://www.pushplus.plus/send?token={self.plusplusToken}&title=bbxy&content={msg}&template=txt"
httpx.get(url=plusplusUrl, params=self.params, headers=self.headers)
print("微信公众号消息已发送")
return True
else:
plusplusUrl = f"http://www.pushplus.plus/send?token={self.plusplusToken}&title=bbxy自动签到&content={self.signSuccessMsg}&template=txt"
httpx.get(url=plusplusUrl, params=self.params, headers=self.headers)
print("微信公众号消息已发送")
return False
if __name__ == '__main__':
"""
主程序
"""
websites = ["https://www.bbxy.buzz/", "https://dash.bbxy.buzz/", "https://bbxy.buzz/",
"https://baibianxiaoying.top/"]
a = AutoBBxySign()
a.check_websites_sync(websites)
a.login()
a.sign()
a.msgTemplate()