A simple Python Pydantic model for Honkai: Star Rail parsed data from the Mihomo API.
A simple Python Pydantic model for Honkai: Star Rail parsed data from the Mihomo API.
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}
pip install -U git+https://github.com/KT-Yeh/mihomo.git
There are two parsed data formats:
client.fetch_user_v1(800333171)mihomo.models.v1.StarrailInfoParsedV1mihomo/models/v1 directory.client.fetch_user(800333171)mihomo.models.StarrailInfoParsedmihomo/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.
…
from mihomo import tools
data = await client.fetch_user(800333171)
data = tools.remove_duplicate_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)
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))