-
Notifications
You must be signed in to change notification settings - Fork 355
/
ck_glados.py
140 lines (124 loc) · 4.49 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
# -*- coding: utf-8 -*-
"""
:author @XFY9326
cron: 11 6 * * *
new Env('GLaDOS');
"""
import traceback
from typing import Optional
import requests
import utils_tmp
from notify_mtr import send
from utils import get_data
class GLaDOS:
def __init__(self, check_items: list):
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: str):
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: str) -> 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",
},
json=payload,
) as r:
return r.json()
def api_status(self, cookies: str) -> 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()
@staticmethod
def get_budget(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 i.get("vip") == vip_level)
or (vip_level is None and "vip" not in i)
]
if user_budgets:
return user_budgets[0]
raise OSError(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_res = self.api_check_in(cookie)
check_in_msg = check_in_res["message"]
if check_in_msg == "\u6ca1\u6709\u6743\u9650":
msg = (
"--------------------\n"
"Msg: Your cookies are expired!\n"
"--------------------"
)
msg_all += msg
continue
status_res = self.api_status(cookie)
# print(status_res)
left_days = int(str(status_res["data"]["leftDays"]).split(".")[0])
vip_level = status_res["data"]["vip"]
traffic_res = self.api_traffic(cookie)
used_gb = traffic_res["data"]["today"] / 1024 / 1024 / 1024
user_budget = self.get_budget(vip_level)
total_gb = user_budget["budget"]
plan = user_budget["level"]
msg = (
"--------------------\n"
f"Msg: {check_in_msg}\n"
f"Plan: {plan} Plan\n"
f"Left days: {left_days}\n"
f"Usage: {used_gb:.3f} GB\n"
f"Total: {total_gb} GB\n"
"--------------------"
)
except Exception:
msg = (
"--------------------\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", [])
result = GLaDOS(check_items=_check_items).main()
send("GLaDOS", result)