NeteaseCloudMusic_PythonSDK/package/NeteaseCloudMusic/help.py
2023-12-11 18:31:07 +08:00

43 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
import pkg_resources
# 载入配置
resource_path = pkg_resources.resource_filename(__name__, 'config.json')
with open(resource_path, 'r', encoding='utf-8') as f:
config = json.loads(f.read())
def api_help(name: str = None) -> str:
"""
获取接口帮助
:param name: 接口名称
:return:
"""
if name is None:
result_str = ("from NeteaseCloudMusic import NeteaseCloudMusicApi, api_help, api_list\n\n"
"netease_cloud_music_api = NeteaseCloudMusicApi() # 初始化API\n"
"netease_cloud_music_api.cookie = YOUR_COOKIE # 设置cookie\n"
"response = netease_cloud_music_api.request(apiName, queryDict) # 调用接口\n\n"
"# Use ”help(apiName)“ to view detailed information about the interface\n"
"# Use ”api_list()“ to view the interface list")
elif name in api_list():
result_str = f'name: {name}\n {config[name]["name"]}\n {config[name]["explain"]}\n\n'
result_str += "query example: \n"
for example in config[name]["example"]:
index = config[name]["example"].index(example)
result_str += f'{json.dumps(config[name]["example"][index]["query"], indent=2, ensure_ascii=False)}\n\n'
else:
result_str = f'apiName: {name} not foundplease use ”api_list()“ to view the interface list'
return result_str
def api_list():
"""
获取接口列表
:return:
"""
return list(config.keys())