Update example code

This commit is contained in:
M-307 2022-07-05 13:38:08 +07:00
parent fff924a50e
commit 9b679faf89
8 changed files with 169 additions and 14 deletions

30
example/artifacts.py Normal file
View File

@ -0,0 +1,30 @@
import asyncio
from enkanetwork import EnkaNetworkAPI
from enkanetwork.enum import EquipmentsType, DigitType
client = EnkaNetworkAPI(lang="th")
async def main():
data = await client.fetch_user(843715177)
for character in data.characters:
print(f"=== Artifacts of {character.name} ===")
for artifact in filter(lambda x: x.type == EquipmentsType.ARTIFACT,character.equipments):
print(f"ID: {artifact.id}")
print(f"Name: {artifact.detail.name}")
print(f"Type: {artifact.detail.artifactType}")
print(f"Icon: {artifact.detail.icon}")
print(f"Level: {artifact.level}")
print("--- Main Stats ---")
print(f"Name: {artifact.detail.mainstats.name}")
print(f"Value: {artifact.detail.mainstats.value}{'%' if artifact.detail.mainstats.type == DigitType.PERCENT else ''}")
print("--- Sub Stats ---")
for substate in artifact.detail.substats:
print(f"Name: {substate.name}")
print(f"Value: {substate.value}{'%' if substate.type == DigitType.PERCENT else ''}")
print("-"*18)
print("="*18)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

22
example/characters.py Normal file
View File

@ -0,0 +1,22 @@
import asyncio
from enkanetwork import EnkaNetworkAPI, Config
client = EnkaNetworkAPI(lang="th")
async def main():
data = await client.fetch_user(843715177)
print("=== Characters ===")
for character in data.characters:
print(f"ID: {character.id}")
print(f"Name: {character.name}")
print(f"Level: {character.level}")
print(f"Ascension: {''*character.ascension}")
print(f"XP: {character.xp}")
print(f"Icon: {character.image.icon}")
print(f"Side icon: {character.image.side}")
print(f"Wish banner: {character.image.gacha}")
print("="*18)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

19
example/constellations.py Normal file
View File

@ -0,0 +1,19 @@
import asyncio
from enkanetwork import EnkaNetworkAPI, Config
client = EnkaNetworkAPI(lang="th")
async def main():
data = await client.fetch_user(843715177)
for character in data.characters:
print(f"=== Constellations of {character.name} ===")
for constellation in character.constellations:
print(f"ID: {constellation.id}")
print(f"Name: {constellation.name}")
print(f"Icon: {constellation.icon}")
print(f"Unlocked: {constellation.unlocked}")
print("="*18)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

View File

@ -1,14 +0,0 @@
import asyncio
from enkanetwork import EnkaNetworkAPI
client = EnkaNetworkAPI()
async def main():
data = await client.fetch_user(843715177)
print(f"Nickname: {data.player.nickname}")
print(f"Level: {data.player.level}")
print(f"Cache timeout: {data.ttl}")
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

26
example/namecards.py Normal file
View File

@ -0,0 +1,26 @@
import asyncio
from enkanetwork import EnkaNetworkAPI, Config
client = EnkaNetworkAPI(lang="th")
async def main():
data = await client.fetch_user(843715177)
print("=== Namecard main ===")
print(f"ID: {data.player.namecard.id}")
print(f"Name: {data.player.namecard.name}")
print(f"Banner URL: {data.player.namecard.banner}")
print(f"Navbar URL: {data.player.namecard.navbar}")
print(f"Icon URL: {data.player.namecard.icon}")
print("\n")
print("=== List Namecard ===")
for namecard in data.player.list_namecard:
print(f"ID: {namecard.id}")
print(f"Name: {namecard.name}")
print(f"Banner URL: {namecard.banner}")
print(f"Navbar URL: {namecard.navbar}")
print(f"Icon URL: {namecard.icon}")
print("-"*18)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

26
example/player.py Normal file
View File

@ -0,0 +1,26 @@
import asyncio
from enkanetwork import EnkaNetworkAPI, Config
client = EnkaNetworkAPI(lang="th")
async def main():
data = await client.fetch_user(843715177)
print("=== Player Info ===")
print(f"Nickname: {data.player.nickname}")
print(f"Level: {data.player.level}")
print(f"Icon: {data.player.profile_picture.icon}")
print(f"Signature: {data.player.signature}")
print(f"Achievement: {data.player.achievement}")
print(f"Abyss floor: {data.player.abyss_floor} - {data.player.abyss_room}")
print(f"Cache timeout: {data.ttl}")
print("=== Characters Preview ===")
for charactersPreview in data.player.characters_preview:
print("ID:", charactersPreview.id)
print("Name:", charactersPreview.name)
print("Icon:", charactersPreview.icon)
print("Level:", charactersPreview.level)
print("="*18)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

19
example/skills.py Normal file
View File

@ -0,0 +1,19 @@
import asyncio
from enkanetwork import EnkaNetworkAPI, Config
client = EnkaNetworkAPI(lang="th")
async def main():
data = await client.fetch_user(843715177)
for character in data.characters:
print(f"=== Skill of {character.name} ===")
for constellation in character.constellations:
print(f"ID: {constellation.id}")
print(f"Name: {constellation.name}")
print(f"Icon: {constellation.icon}")
print(f"Unlocked: {constellation.unlocked}")
print("="*18)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

27
example/weapon.py Normal file
View File

@ -0,0 +1,27 @@
import asyncio
from enkanetwork import EnkaNetworkAPI
from enkanetwork.enum import DigitType
client = EnkaNetworkAPI(lang="th")
async def main():
data = await client.fetch_user(843715177)
for character in data.characters:
print(f"=== Weapon of {character.name} ===")
weapon = character.equipments[-1]
print(f"ID: {weapon.id}")
print(f"Name: {weapon.detail.name}")
print(f"Icon: {weapon.detail.icon}")
print(f"Level: {weapon.level}")
print("--- Main Stats ---")
print(f"Name: {weapon.detail.mainstats.name}")
print(f"Value: {weapon.detail.mainstats.value}{'%' if weapon.detail.mainstats.type == DigitType.PERCENT else ''}")
print("--- Sub Stats ---")
for substate in weapon.detail.substats:
print(f"Name: {substate.name}")
print(f"Value: {substate.value}{'%' if substate.type == DigitType.PERCENT else ''}")
print("-"*18)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())