-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add examples and update README.md
- Loading branch information
Showing
5 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import asyncio | ||
|
||
from mihomo import Language, MihomoAPI | ||
|
||
client = MihomoAPI(language=Language.EN) | ||
|
||
|
||
async def main(): | ||
data = await client.fetch_user(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)}") | ||
|
||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import asyncio | ||
import pickle | ||
import zlib | ||
|
||
from mihomo import Language, MihomoAPI, StarrailInfoParsed | ||
|
||
|
||
async def main(): | ||
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)) | ||
|
||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import asyncio | ||
|
||
from mihomo import Language, MihomoAPI, tools | ||
|
||
|
||
async def main(): | ||
client = MihomoAPI(language=Language.EN) | ||
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) | ||
|
||
print(data) | ||
|
||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters