From 1b79ee61994c43ba29826484a44d39fc7bbd9293 Mon Sep 17 00:00:00 2001 From: helloplhm-qwq Date: Sat, 6 Jan 2024 18:22:05 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E4=BC=98=E7=A7=80=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 93 ++++++++++++++++++++++++++++++++++++++++++ common/Httpx.py | 2 +- modules/wy/__init__.py | 2 +- 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 558bd57..0f77fbf 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ **主开发是高一住校学生,只有周末有时间回复,也欢迎所有人来贡献代码,我们在这里万分感谢** +**临近期末考试,更新会放缓,新功能请不要催得太紧** + ## 部署方法 ### poetry部署 @@ -98,6 +100,97 @@ docker inspect lx-music-api-server-python | 429 | 请求过于频繁 | | 500 | 服务器内部错误(对应 body.code 4) | +## 备注 + +### 本项目中可能会出现以下优秀代码 + +1. 三角形具有稳定性 +```python +for a in xxx: + if (xxx): + if (xxx): + if (xxx): + for b in xxx: + if (xxx): + while (xxx): + pass + pass + pass + pass + pass + pass + pass +``` + +2. 能一行写完那就坚决不多行 +```python +sys.stdout.write('\r|'+'=' * (int(dd['pares'].index(ds) / total * 50)) + ' ' * (49 - int(dd['pares'].index(ds) / total * 50)) + f'''|{int(dd['pares'].index(ds) / total * 100)}% xx''' + ds['title']+' ' * 20) +``` + +3. 不复用重复部分 +```python +async def other(method, source, songid, _): + try: + func = require('modules.' + source + '.' + method) + except: + return { + 'code': 1, + 'msg': '未知的源或不支持的方法', + 'data': None, + } + try: + result = await func(songid) + return { + 'code': 0, + 'msg': 'success', + 'data': result + } + except FailedException as e: + return { + 'code': 2, + 'msg': e.args[0], + 'data': None, + } + +async def other_with_query(method, source, t, _, query): + try: + func = require('modules.' + source + '.' + method) + except: + return { + 'code': 1, + 'msg': '未知的源或不支持的方法', + 'data': None, + } + try: + result = await func(t, query) + return { + 'code': 0, + 'msg': 'success', + 'data': result + } + except FailedException as e: + return { + 'code': 2, + 'msg': e.args[0], + 'data': None, + } +``` + +4. 模块不拆分 +详见[config.py](https://github.com/lxmusics/lx-music-api-server-python/tree/main/common/config.py) + +5. 不明所以的变量名 +```python +a = '小明' +b = 1 +c = 2 +d = b'' +def e(a, b, c): + c = xxx + d = xxx +f = e(c, b, a) +``` + ## 项目协议 本项目基于 [MIT](https://github.com/lxmusics/lx-music-api-server/blob/main/LICENSE) 许可证发行,以下协议是对于 MIT 原协议的补充,如有冲突,以以下协议为准。 diff --git a/common/Httpx.py b/common/Httpx.py index f80ef84..1511e29 100644 --- a/common/Httpx.py +++ b/common/Httpx.py @@ -226,7 +226,7 @@ async def AsyncRequest(url, options = {}): - : 缓存可用秒数 - cache-ignore: 缓存忽略关键字 - @ return: requests.Response类型的响应数据 + @ return: common.Httpx.ClientResponse类型的响应数据 ''' if (not variable.aioSession): variable.aioSession = aiohttp.ClientSession() diff --git a/modules/wy/__init__.py b/modules/wy/__init__.py index 3f87933..552d899 100644 --- a/modules/wy/__init__.py +++ b/modules/wy/__init__.py @@ -41,7 +41,7 @@ async def url(songId, quality): req = await Httpx.AsyncRequest(requestUrl, { 'method': 'POST', 'headers': { - 'Cookie': config.read_config('module.wy.cookie') if (not variable.use_cookie_pool) else random.choice(config.read_config('module.cookiepool.wy'))['cookie'], + 'Cookie': config.read_config('module.wy.user.cookie') if (not variable.use_cookie_pool) else random.choice(config.read_config('module.cookiepool.wy'))['cookie'], }, 'form': eapiEncrypt(path, json.dumps({ "ids": json.dumps([songId]),