Skip to content

Commit

Permalink
docs: 优秀代码
Browse files Browse the repository at this point in the history
  • Loading branch information
helloplhm-qwq committed Jan 6, 2024
1 parent da3384b commit 1b79ee6
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

**主开发是高一住校学生,只有周末有时间回复,也欢迎所有人来贡献代码,我们在这里万分感谢**

**临近期末考试,更新会放缓,新功能请不要催得太紧**

## 部署方法

### poetry部署
Expand Down Expand Up @@ -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 原协议的补充,如有冲突,以以下协议为准。
Expand Down
2 changes: 1 addition & 1 deletion common/Httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async def AsyncRequest(url, options = {}):
- <int>: 缓存可用秒数
- cache-ignore: <list> 缓存忽略关键字
@ return: requests.Response类型的响应数据
@ return: common.Httpx.ClientResponse类型的响应数据
'''
if (not variable.aioSession):
variable.aioSession = aiohttp.ClientSession()
Expand Down
2 changes: 1 addition & 1 deletion modules/wy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down

0 comments on commit 1b79ee6

Please sign in to comment.