Skip to content

Commit

Permalink
🎨 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Oreomeow committed Oct 21, 2021
1 parent fa1d79b commit 2ffcb2b
Show file tree
Hide file tree
Showing 19 changed files with 137 additions and 155 deletions.
12 changes: 6 additions & 6 deletions api_leetcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def main():
"__typename } lastSubmission { id __typename } date userStatus __typename }} ",
},
)
leetcodeTitle = (
leetcode_title = (
json.loads(response.text)
.get("data")
.get("todayRecord")[0]
Expand All @@ -36,12 +36,12 @@ def main():
)

# 获取今日每日一题的所有信息
url = base_url + "/problems/" + leetcodeTitle
url = base_url + "/problems/" + leetcode_title
response = requests.post(
base_url + "/graphql",
json={
"operationName": "questionData",
"variables": {"titleSlug": leetcodeTitle},
"variables": {"titleSlug": leetcode_title},
"query": "query questionData($titleSlug: String!) { question(titleSlug: $titleSlug) { "
" questionId questionFrontendId boundTopicId title titleSlug "
"content translatedTitle translatedContent isPaidOnly difficulty "
Expand All @@ -59,12 +59,12 @@ def main():
},
)
# 转化成json格式
jsonText = json.loads(response.text).get("data").get("question")
json_text = json.loads(response.text).get("data").get("question")
# 题目题号
num = jsonText.get("questionFrontendId")
# 题名(中文)
leetcodeTitle = jsonText.get("translatedTitle")
msg = num + "." + leetcodeTitle
leetcode_title = json_text.get("translatedTitle")
msg = num + "." + leetcode_title
return f"{msg}\n{url}"


Expand Down
2 changes: 1 addition & 1 deletion ck_baidu_url_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def url_submit(data_url: str, submit_url: str, times: int = 100) -> str:
remian = 100000
success_count = 0
error_count = 0
for one in range(times):
for _ in range(times):
try:
response = requests.post(url=submit_url, data=urls_data)
if response.json().get("success"):
Expand Down
6 changes: 3 additions & 3 deletions ck_bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ def get_nav(session):
url = "https://api.bilibili.com/x/web-interface/nav"
ret = session.get(url=url).json()
uname = ret.get("data", {}).get("uname")
"""
uid = ret.get("data", {}).get("mid")
is_login = ret.get("data", {}).get("isLogin")
"""
coin = ret.get("data", {}).get("money")
vip_type = ret.get("data", {}).get("vipType")
current_exp = ret.get("data", {}).get("level_info", {}).get("current_exp")
return uname, uid, is_login, coin, vip_type, current_exp
return uname, coin, vip_type, current_exp

@staticmethod
def reward(session) -> dict:
Expand Down Expand Up @@ -359,8 +361,6 @@ def main(self):
live_stats = self.live_status(session=session)
(
uname,
uid,
is_login,
new_coin,
vip_type,
new_current_exp,
Expand Down
4 changes: 2 additions & 2 deletions ck_duokan.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def gift(self, cookies):

def add_draw(self, cookies):
success_count = 0
for one in range(6):
for _ in range(6):
url = "https://www.duokan.com/store/v0/event/chances/add"
data = (
f"code=8ulcky4bknbe_f&count=1&{self.get_data(cookies=cookies)}&withid=1"
Expand All @@ -332,7 +332,7 @@ def add_draw(self, cookies):

def draw(self, cookies):
success_count = 0
for one in range(6):
for _ in range(6):
url = "https://www.duokan.com/store/v0/event/drawing"
data = f"code=8ulcky4bknbe_f&{self.get_data(cookies=cookies)}&withid=1"
response = requests.post(
Expand Down
12 changes: 6 additions & 6 deletions ck_euserv.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def handle_captcha_solved_result(self, solved: dict) -> str:
operator = "*"
if operator_pos != -1:
left_part = text[:operator_pos]
right_part = text[operator_pos + 1:]
right_part = text[operator_pos + 1 :]
if left_part.isdigit() and right_part.isdigit():
return eval(
"{left} {operator} {right}".format(
Expand Down Expand Up @@ -140,7 +140,7 @@ def login(
password: str,
userid: str,
apikey: str,
CHECK_CAPTCHA_SOLVER_USAGE: bool,
check_captcha_solver_usage: bool,
) -> tuple:
headers = {"user-agent": self.user_agent, "origin": "https://www.euserv.com"}
url = "https://support.euserv.com/index.iphp"
Expand Down Expand Up @@ -183,7 +183,7 @@ def login(
captcha_code = self.handle_captcha_solved_result(solved_result)
log("[Captcha Solver] 识别的验证码是: {}".format(captcha_code))

if CHECK_CAPTCHA_SOLVER_USAGE:
if check_captcha_solver_usage:
usage = self.get_captcha_solver_usage(userid, apikey)
log(
"[Captcha Solver] current date {0} api usage count: {1}".format(
Expand Down Expand Up @@ -215,7 +215,7 @@ def login(
else:
return sess_id, session

def get_servers(self, sess_id: str, session: requests.session) -> tuple:
def get_servers(self, sess_id: str, session: requests.session) -> dict:
d = {}
url = "https://support.euserv.com/index.iphp?sess_id=" + sess_id
headers = {"user-agent": self.user_agent, "origin": "https://www.euserv.com"}
Expand Down Expand Up @@ -295,13 +295,13 @@ def main(self):
for check_item in self.check_items:
username = check_item.get("username")
password = check_item.get("password")
CHECK_CAPTCHA_SOLVER_USAGE = check_item.get("captcha")
check_captcha_solver_usage = check_item.get("captcha")
userid = check_item.get("userid")
apikey = check_item.get("apikey")
log("*" * 12)
log("[EUserv] 正在续费第 %d 个账号" % (i + 1))
sessid, s = self.login(
username, password, userid, apikey, CHECK_CAPTCHA_SOLVER_USAGE
username, password, userid, apikey, check_captcha_solver_usage
)
if sessid == "-1":
log("[EUserv] 第 %d 个账号登陆失败,请检查登录信息" % (i + 1))
Expand Down
2 changes: 1 addition & 1 deletion ck_fmapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def sign(headers):
msg = response.get("message")
except Exception as e:
print("错误信息", str(e))
msg = "未知错误,检查日志"
msg = f"未知错误{str(e)}"
return msg

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions ck_game163.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, check_items):
self.check_items = check_items

@staticmethod
def game163(authorization):
def checkin(authorization):
url = "http://n.cg.163.com/api/v2/sign-today"
headers = {
"user-agent": "Mozilla/5.0 (Linux; Android 10; Redmi K30 Build/QKQ1.190825.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/85.0.4183.127 Mobile Safari/537.36",
Expand All @@ -31,7 +31,7 @@ def main(self):
msg_all = ""
for check_item in self.check_items:
authorization = str(check_item.get("authorization"))
msg = self.game163(authorization=authorization)
msg = self.checkin(authorization=authorization)
msg_all += msg + "\n\n"
return msg_all

Expand Down
2 changes: 1 addition & 1 deletion ck_glados.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def main(self):
+ "GB\n"
"--------------------"
)
except BaseException:
except Exception:
msg = (
"--------------------\n"
"GLaDOS \n"
Expand Down
Loading

0 comments on commit 2ffcb2b

Please sign in to comment.