MetaCubeX/mihomo
Fork: 2660 Star: 16731 (更新于 2024-11-21 02:19:13)
license: MIT
Language: Python .
A simple Python Pydantic model for Honkai: Star Rail parsed data from the Mihomo API.
最后发布版本: v1.18.10 ( 2024-11-03 17:24:36)
mihomo
A simple python pydantic model (type hint and autocompletion support) for Honkai: Star Rail parsed data from the Mihomo API.
API url: https://api.mihomo.me/sr_info_parsed/{UID}?lang={LANG}
Installation
pip install -U git+https://github.com/KT-Yeh/mihomo.git
Usage
Basic
There are two parsed data formats:
- V1:
- URL: https://api.mihomo.me/sr_info_parsed/800333171?lang=en&version=v1
- Fetching: use
client.fetch_user_v1(800333171)
- Data model:
mihomo.models.v1.StarrailInfoParsedV1
- All models defined in
mihomo/models/v1
directory.
- V2:
- URL: https://api.mihomo.me/sr_info_parsed/800333171?lang=en
- Fetching: use
client.fetch_user(800333171)
- Data model:
mihomo.models.StarrailInfoParsed
- All models defined in
mihomo/models
directory.
If you don't want to use client.get_icon_url
to get the image url everytime, you can use client.fetch_user(800333171, replace_icon_name_with_url=True)
to get the parsed data with asset urls.
Example
import asyncio
from mihomo import Language, MihomoAPI
from mihomo.models import StarrailInfoParsed
from mihomo.models.v1 import StarrailInfoParsedV1
client = MihomoAPI(language=Language.EN)
async def v1():
data: StarrailInfoParsedV1 = await client.fetch_user_v1(800333171)
print(f"Name: {data.player.name}")
print(f"Level: {data.player.level}")
print(f"Signature: {data.player.signature}")
print(f"Achievements: {data.player_details.achievements}")
print(f"Characters count: {data.player_details.characters}")
print(f"Profile picture url: {client.get_icon_url(data.player.icon)}")
for character in data.characters:
print("-----------")
print(f"Name: {character.name}")
print(f"Rarity: {character.rarity}")
print(f"Level: {character.level}")
print(f"Avatar url: {client.get_icon_url(character.icon)}")
print(f"Preview url: {client.get_icon_url(character.preview)}")
print(f"Portrait url: {client.get_icon_url(character.portrait)}")
async def v2():
data: StarrailInfoParsed = await client.fetch_user(800333171, replace_icon_name_with_url=True)
print(f"Name: {data.player.name}")
print(f"Level: {data.player.level}")
print(f"Signature: {data.player.signature}")
print(f"Profile picture url: {data.player.avatar.icon}")
for character in data.characters:
print("-----------")
print(f"Name: {character.name}")
print(f"Rarity: {character.rarity}")
print(f"Portrait url: {character.portrait}")
asyncio.run(v1())
asyncio.run(v2())
Tools
from mihomo import tools
Remove Duplicate Character
data = await client.fetch_user(800333171)
data = tools.remove_duplicate_character(data)
Merge Character Data
old_data = await client.fetch_user(800333171)
# Change characters in game and wait for the API to refresh
# ...
new_data = await client.fetch_user(800333171)
data = tools.merge_character_data(new_data, old_data)
Data Persistence
Take pickle and json as an example
import pickle
import zlib
from mihomo import MihomoAPI, Language, StarrailInfoParsed
client = MihomoAPI(language=Language.EN)
data = await client.fetch_user(800333171)
# Save
pickle_data = zlib.compress(pickle.dumps(data))
print(len(pickle_data))
json_data = data.json(by_alias=True, ensure_ascii=False)
print(len(json_data))
# Load
data_from_pickle = pickle.loads(zlib.decompress(pickle_data))
data_from_json = StarrailInfoParsed.parse_raw(json_data)
print(type(data_from_pickle))
print(type(data_from_json))
最近版本更新:(数据更新于 2024-11-22 04:19:17)
2024-11-03 17:24:36 v1.18.10
2024-09-29 17:47:55 v1.18.9
2024-09-02 16:38:59 v1.18.8
2024-08-13 01:01:02 Prerelease-Alpha
2024-07-28 13:50:26 v1.18.7
2024-07-01 23:05:34 v1.18.6
2024-05-19 16:50:46 v1.18.5
2024-05-18 23:32:02 v1.18.5
2024-05-18 19:13:53 v1.18.5
2024-04-29 14:24:11 v1.18.4
主题(topics):
honkai-star-rail, mihomo, python, star-rail-api
MetaCubeX/mihomo同语言 Python最近更新仓库
2024-11-22 02:39:01 goauthentik/authentik
2024-11-22 00:03:47 comfyanonymous/ComfyUI
2024-11-21 22:06:18 rashevskyv/dbi
2024-11-21 21:09:02 xtekky/gpt4free
2024-11-21 20:03:58 ultralytics/ultralytics
2024-11-21 00:54:04 hect0x7/JMComic-Crawler-Python