forked from OreosLab/checkinpanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ck_glados.py
150 lines (134 loc) · 4.8 KB
/
ck_glados.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# -*- coding: utf-8 -*-
"""
:author @XFY9326
cron: 11 6 * * *
new Env('GLaDOS');
"""
import json
import traceback
from typing import Optional
import requests
import utils_tmp
from notify_mtr import send
from utils import get_data
class GLaDOS(object):
def __init__(self, check_items):
self.check_items = check_items
self.original_url = "https://glados.rocks"
self.UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
def api_traffic(self, cookies):
traffic_url = f"{self.original_url}/api/user/traffic"
referer_url = f"{self.original_url}/console"
with requests.get(
traffic_url,
headers={
"cookie": cookies,
"referer": referer_url,
"origin": self.original_url,
"user-agent": self.UA,
"content-type": "application/json;charset=UTF-8",
},
) as r:
return r.json()
def api_check_in(self, cookies) -> dict:
check_in_url = f"{self.original_url}/api/user/checkin"
referer_url = f"{self.original_url}/console/checkin"
payload = {"token": "glados_network"}
with requests.post(
check_in_url,
headers={
"cookie": cookies,
"referer": referer_url,
"origin": self.original_url,
"user-agent": self.UA,
"content-type": "application/json;charset=UTF-8",
},
data=json.dumps(payload),
) as r:
return r.json()
def api_status(self, cookies) -> dict:
status_url = f"{self.original_url}/api/user/status"
referer_url = f"{self.original_url}/console/checkin"
with requests.get(
status_url,
headers={
"cookie": cookies,
"referer": referer_url,
"origin": self.original_url,
"user-agent": self.UA,
},
) as r:
return r.json()
def get_budget(self, vip_level: Optional[int]) -> dict:
budget_info = utils_tmp.budget_list
user_budgets = [
i
for i in budget_info
if (vip_level is not None and "vip" in i and i["vip"] == vip_level)
or (vip_level is None and "vip" not in i)
]
if len(user_budgets) > 0:
return user_budgets[0]
else:
raise EnvironmentError(
f"Budget info not found for this user! VIP: {vip_level}"
)
def main(self):
msg_all = ""
for check_item in self.check_items:
cookie = check_item.get("cookie")
try:
check_in_response = self.api_check_in(cookie)
check_in_msg = check_in_response["message"]
if check_in_msg == "\u6ca1\u6709\u6743\u9650":
msg = (
"--------------------\n"
"GLaDOS \n"
"Msg: Your cookies are expired!\n"
"--------------------"
)
status_response = self.api_status(cookie)
left_days = int(status_response["data"]["leftDays"].split(".")[0])
vip_level = status_response["data"]["vip"]
traffic_response = self.api_traffic(cookie)
used_gb = traffic_response["data"]["today"] / 1024 / 1024 / 1024
user_budget = self.get_budget(vip_level)
total_gb = user_budget["budget"]
plan = user_budget["level"]
msg = (
"--------------------\n"
"GLaDOS \n"
+ "Msg: "
+ check_in_msg
+ "\n"
+ "Plan: "
+ plan
+ " Plan\n"
+ "Left days: "
+ str(left_days)
+ "\n"
+ "Usage: "
+ "%.3f" % used_gb
+ "GB\n"
+ "Total: "
+ str(total_gb)
+ "GB\n"
"--------------------"
)
except Exception:
msg = (
"--------------------\n"
"GLaDOS \n"
"Msg: Check in error!\n"
"Error:\n"
f"{traceback.format_exc()}"
"\n"
"--------------------"
)
msg_all += msg + "\n\n"
return msg_all
if __name__ == "__main__":
data = get_data()
_check_items = data.get("GLADOS", [])
res = GLaDOS(check_items=_check_items).main()
send("GLaDOS", res)