mirror of
https://github.com/MeoProject/lx-music-api-server.git
synced 2025-05-23 19:17:41 +08:00
docs: 优秀代码
This commit is contained in:
parent
da3384b6d4
commit
1b79ee6199
93
README.md
93
README.md
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
**主开发是高一住校学生,只有周末有时间回复,也欢迎所有人来贡献代码,我们在这里万分感谢**
|
**主开发是高一住校学生,只有周末有时间回复,也欢迎所有人来贡献代码,我们在这里万分感谢**
|
||||||
|
|
||||||
|
**临近期末考试,更新会放缓,新功能请不要催得太紧**
|
||||||
|
|
||||||
## 部署方法
|
## 部署方法
|
||||||
|
|
||||||
### poetry部署
|
### poetry部署
|
||||||
@ -98,6 +100,97 @@ docker inspect lx-music-api-server-python
|
|||||||
| 429 | 请求过于频繁 |
|
| 429 | 请求过于频繁 |
|
||||||
| 500 | 服务器内部错误(对应 body.code 4) |
|
| 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 原协议的补充,如有冲突,以以下协议为准。
|
本项目基于 [MIT](https://github.com/lxmusics/lx-music-api-server/blob/main/LICENSE) 许可证发行,以下协议是对于 MIT 原协议的补充,如有冲突,以以下协议为准。
|
||||||
|
@ -226,7 +226,7 @@ async def AsyncRequest(url, options = {}):
|
|||||||
- <int>: 缓存可用秒数
|
- <int>: 缓存可用秒数
|
||||||
- cache-ignore: <list> 缓存忽略关键字
|
- cache-ignore: <list> 缓存忽略关键字
|
||||||
|
|
||||||
@ return: requests.Response类型的响应数据
|
@ return: common.Httpx.ClientResponse类型的响应数据
|
||||||
'''
|
'''
|
||||||
if (not variable.aioSession):
|
if (not variable.aioSession):
|
||||||
variable.aioSession = aiohttp.ClientSession()
|
variable.aioSession = aiohttp.ClientSession()
|
||||||
|
@ -41,7 +41,7 @@ async def url(songId, quality):
|
|||||||
req = await Httpx.AsyncRequest(requestUrl, {
|
req = await Httpx.AsyncRequest(requestUrl, {
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
'headers': {
|
'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({
|
'form': eapiEncrypt(path, json.dumps({
|
||||||
"ids": json.dumps([songId]),
|
"ids": json.dumps([songId]),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user