Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/maimai/libraries/maimaidx_api_data.py

45 lines
1.3 KiB
Python
Raw Normal View History

2023-06-16 15:15:47 +00:00
from core.utils.http import get_url
async def get_alias(input, get_music = False):
url = f"https://download.fanyu.site/maimai/alias.json"
data = await get_url(url, 200, fmt='json')
result = []
if get_music:
if input in data:
result = data[input]
else:
result = list(data.keys())
return result
async def get_rank(msg, player):
url = f"https://www.diving-fish.com/api/maimaidxprober/rating_ranking"
data = await get_url(url, 200, fmt='json')
rate = None
rank = None
total_rate = 0
2023-06-16 16:25:18 +00:00
sorted_data = sorted(data, key=lambda x: x['ra'], reverse=True)
for i, scoreboard in enumerate(sorted_data):
if scoreboard['username'].lower() == player.lower():
username = scoreboard['username']
2023-06-16 15:15:47 +00:00
rate = scoreboard['ra']
rank = i + 1
total_rate += scoreboard['ra']
2023-06-16 16:25:18 +00:00
average_rate = total_rate / len(sorted_data)
2023-06-16 15:15:47 +00:00
2023-06-16 15:34:58 +00:00
if rank is None:
rank = 0
2023-06-16 16:25:18 +00:00
surpassing_rate = (len(sorted_data) - rank) / len(sorted_data) * 100
2023-06-16 15:15:47 +00:00
2023-06-16 15:34:58 +00:00
if rate is None:
2023-06-16 15:15:47 +00:00
await msg.finish(msg.locale.t('maimai.message.user_not_found'))
return None
2023-06-16 16:25:18 +00:00
return username, rate, rank, average_rate, surpassing_rate