From 2d2480f1164d3b7343b2d2463c3dd4052117e558 Mon Sep 17 00:00:00 2001 From: Hobr Date: Sat, 16 Nov 2024 12:48:44 +0800 Subject: [PATCH] chore: format --- interface/CLI/product.py | 5 ++++- interface/CLI/setting.py | 6 +++++- interface/CLI/user.py | 6 +++++- pyproject.toml | 14 -------------- util/Bilibili/__init__.py | 16 +++++++++------- util/Notice/__init__.py | 6 +++++- util/Request/__init__.py | 24 ++++++++++++++++++++---- util/Task/__init__.py | 5 ++--- 8 files changed, 50 insertions(+), 32 deletions(-) diff --git a/interface/CLI/product.py b/interface/CLI/product.py index 83ad698..3075085 100644 --- a/interface/CLI/product.py +++ b/interface/CLI/product.py @@ -166,6 +166,9 @@ def FilenameStep(name: str) -> str: skuId, skuSelected = SkuStep(screenId=self.config["screenId"]) self.config["skuId"] = skuId - self.conf.Save(FilenameStep(name=f"{self.info.Project()['name']} ({skuSelected})"), self.config) + self.conf.Save( + FilenameStep(name=f"{self.info.Project()['name']} ({skuSelected})"), + self.config, + ) logger.info("【商品配置初始化】配置已保存!") return self.config diff --git a/interface/CLI/setting.py b/interface/CLI/setting.py index c547214..c0ff712 100644 --- a/interface/CLI/setting.py +++ b/interface/CLI/setting.py @@ -249,7 +249,11 @@ def FilenameStep() -> str: """ 文件名 """ - default = re.sub(r'[\\/*?:"<>|]', "_", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) + default = re.sub( + r'[\\/*?:"<>|]', + "_", + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), + ) filename = self.data.Inquire( type="Text", message="保存的设置文件名称", diff --git a/interface/CLI/user.py b/interface/CLI/user.py index 8ee2e45..d1a8702 100644 --- a/interface/CLI/user.py +++ b/interface/CLI/user.py @@ -221,5 +221,9 @@ def FilenameStep(name: str) -> str: self.config["deliver"] = DeliverStep() self.config["phone"] = PhoneStep() self.config["userinfo"] = self.info.Userinfo() - self.conf.Save(FilenameStep(name=self.config["buyer"][0]["name"]), self.config, encrypt=self.isEncrypt) + self.conf.Save( + FilenameStep(name=self.config["buyer"][0]["name"]), + self.config, + encrypt=self.isEncrypt, + ) return self.config diff --git a/pyproject.toml b/pyproject.toml index 832e211..d7d231c 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,20 +46,6 @@ pygraphviz = "^1.13" [tool.ruff] line-length = 190 -[tool.ruff.lint] -select = ["B", "C4", "C9", "E", "F", "I", "PL", "S", "SIM", "U", "W", "YTT"] -ignore = ["B006", "S311", "S501"] - -[tool.ruff.lint.mccabe] -max-complexity = 20 - -[tool.ruff.lint.pylint] -max-args = 10 -max-statements = 72 -max-returns = 7 -max-branches = 13 -allow-magic-value-types = ["int","str"] - [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" diff --git a/util/Bilibili/__init__.py b/util/Bilibili/__init__.py index 4d3a23a..80ca8a7 100644 --- a/util/Bilibili/__init__.py +++ b/util/Bilibili/__init__.py @@ -278,8 +278,7 @@ def QueryPrice(self) -> None: url = f"https://show.bilibili.com/api/ticket/project/getV2?version=134&id={self.projectId}&project_id={self.projectId}&requestSource={self.scene}" res = self.net.Response(method="get", url=url) code = res["errno"] - msg = res["msg"] - + match code: # 成功 case 0: @@ -297,16 +296,15 @@ def QueryPrice(self) -> None: # 没保存Screen/Sku位置 else: - for i, screen in enumerate(data["screen_list"]): + for _i, screen in enumerate(data["screen_list"]): if screen["id"] == self.screenId: - self.deliverFee = max(screen["express_fee"], 0) - for j, sku in enumerate(screen["ticket_list"]): + for _j, sku in enumerate(screen["ticket_list"]): if sku["id"] == self.skuId: - self.cost = sku["price"] break + break case _: self.cost = 0 @@ -374,7 +372,11 @@ def CreateOrder(self) -> tuple: # 未预填收货联系人信息 case 209001: self.ContactNeed = True - tmp = self.net.Response(method="post", url="https://show.bilibili.com/api/ticket/buyer/saveContactInfo", params={"username": self.userinfo["username"], "tel": self.phone}) + tmp = self.net.Response( + method="post", + url="https://show.bilibili.com/api/ticket/buyer/saveContactInfo", + params={"username": self.userinfo["username"], "tel": self.phone}, + ) if tmp["errno"] == 0: logger.info("【创建订单】已自动设置收货联系人信息") diff --git a/util/Notice/__init__.py b/util/Notice/__init__.py index 5fe222c..ef8f1fb 100644 --- a/util/Notice/__init__.py +++ b/util/Notice/__init__.py @@ -102,7 +102,11 @@ def Ding(self, token: str) -> None: 钉钉 """ url = f"https://oapi.dingtalk.com/robot/send?access_token={token}" - data = {"msgtype": "text", "text": {"content": self.message}, "at": {"isAtAll": False}} + data = { + "msgtype": "text", + "text": {"content": self.message}, + "at": {"isAtAll": False}, + } self.net.Response(method="post", url=url, params=data) @logger.catch diff --git a/util/Request/__init__.py b/util/Request/__init__.py index ad1d6a4..d751937 100644 --- a/util/Request/__init__.py +++ b/util/Request/__init__.py @@ -88,17 +88,33 @@ def Response(self, method: str, url: str, params: dict = {}, isJson: bool = True try: if isJson: - dist = methods[method](url=url, **({"params": params} if method == "get" else {"data": params})) + dist = methods[method]( + url=url, + **({"params": params} if method == "get" else {"data": params}), + ) if dist.status_code == 200: return dist.json() else: - return {"code": 114514, "errno": 114514, "msg": f"请求错误: {dist.status_code}", "message": f"请求错误: {dist.status_code}"} + return { + "code": 114514, + "errno": 114514, + "msg": f"请求错误: {dist.status_code}", + "message": f"请求错误: {dist.status_code}", + } else: - methods[method](url=url, **({"params": params} if method == "get" else {"data": params})) + methods[method]( + url=url, + **({"params": params} if method == "get" else {"data": params}), + ) return {} except (httpx.RequestError, httpx.HTTPStatusError, httpx.StreamError) as e: - return {"code": 114514, "errno": 114514, "msg": f"请求错误: {e}", "message": f"请求错误: {e}"} + return { + "code": 114514, + "errno": 114514, + "msg": f"请求错误: {e}", + "message": f"请求错误: {e}", + } @logger.catch def GetCookie(self) -> dict: diff --git a/util/Task/__init__.py b/util/Task/__init__.py index 5aca557..f2803bf 100644 --- a/util/Task/__init__.py +++ b/util/Task/__init__.py @@ -255,7 +255,7 @@ def WaitAvailableAction(self) -> None: if countdown > 0: logger.warning("【等待开票】请确保本机时间是北京时间, 服务器用户尤其要注意!") self.countdownOver = False - + while countdown > 0: countdown = start_time - int(time()) @@ -283,7 +283,7 @@ def WaitAvailableAction(self) -> None: elif countdown < 1: logger.info("【等待开票】即将开票!") sleep(countdown) - + # 预处理 if countdown == 30: self.api.QueryPrice() @@ -337,7 +337,6 @@ def QueryTokenAction(self) -> None: self.queryCache = True logger.info("【获取Token】已缓存商品信息") - @logger.catch def RiskProcessAction(self) -> None: """