mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-12-22 15:47:59 +08:00
docs: Update README.md and examples.
This commit is contained in:
parent
2fd4d7e2e0
commit
51968448e5
43
README.md
43
README.md
@ -1,5 +1,5 @@
|
|||||||
# mihomo
|
# mihomo
|
||||||
A simple Python Pydantic model (type hint and autocompletion support) 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}
|
API url: https://api.mihomo.me/sr_info_parsed/{UID}?lang={LANG}
|
||||||
|
|
||||||
@ -11,17 +11,33 @@ pip install -U git+https://github.com/KT-Yeh/mihomo.git
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Basic
|
### Basic
|
||||||
An example for https://api.mihomo.me/sr_info_parsed/800333171?lang=en
|
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
|
||||||
```py
|
```py
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from mihomo import MihomoAPI, Language
|
from mihomo import Language, MihomoAPI
|
||||||
|
from mihomo.models import StarrailInfoParsed
|
||||||
|
from mihomo.models.v1 import StarrailInfoParsedV1
|
||||||
|
|
||||||
client = MihomoAPI(language=Language.EN)
|
client = MihomoAPI(language=Language.EN)
|
||||||
|
|
||||||
async def main():
|
|
||||||
data = await client.fetch_user(800333171)
|
async def v1():
|
||||||
|
data: StarrailInfoParsedV1 = await client.fetch_user_v1(800333171)
|
||||||
|
|
||||||
print(f"Name: {data.player.name}")
|
print(f"Name: {data.player.name}")
|
||||||
print(f"Level: {data.player.level}")
|
print(f"Level: {data.player.level}")
|
||||||
@ -38,7 +54,22 @@ async def main():
|
|||||||
print(f"Preview url: {client.get_icon_url(character.preview)}")
|
print(f"Preview url: {client.get_icon_url(character.preview)}")
|
||||||
print(f"Portrait url: {client.get_icon_url(character.portrait)}")
|
print(f"Portrait url: {client.get_icon_url(character.portrait)}")
|
||||||
|
|
||||||
asyncio.run(main())
|
|
||||||
|
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
|
### Tools
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from mihomo import Language, MihomoAPI
|
from mihomo import Language, MihomoAPI
|
||||||
|
from mihomo.models import StarrailInfoParsed
|
||||||
|
from mihomo.models.v1 import StarrailInfoParsedV1
|
||||||
|
|
||||||
client = MihomoAPI(language=Language.EN)
|
client = MihomoAPI(language=Language.EN)
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def v1():
|
||||||
data = await client.fetch_user(800333171)
|
data: StarrailInfoParsedV1 = await client.fetch_user_v1(800333171)
|
||||||
|
|
||||||
print(f"Name: {data.player.name}")
|
print(f"Name: {data.player.name}")
|
||||||
print(f"Level: {data.player.level}")
|
print(f"Level: {data.player.level}")
|
||||||
@ -24,4 +26,19 @@ async def main():
|
|||||||
print(f"Portrait url: {client.get_icon_url(character.portrait)}")
|
print(f"Portrait url: {client.get_icon_url(character.portrait)}")
|
||||||
|
|
||||||
|
|
||||||
asyncio.run(main())
|
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())
|
||||||
|
Loading…
Reference in New Issue
Block a user