acurtis166 / SPNKr

Python API for retrieving Halo Infinite multiplayer data
https://acurtis166.github.io/SPNKr/
MIT License
3 stars 2 forks source link

Add `HaloInfiniteClient` wrapper for match-related API requests. #19

Closed acurtis166 closed 10 months ago

acurtis166 commented 10 months ago

@aapokaapo Let me know what you think of this for #15

from aiohttp import ClientSession

from spnkr.client import HaloInfiniteClient
from spnkr.match import Match

async with ClientSession() as session:
    client = HaloInfiniteClient(...)
    match = Match(client, "ca19c433-a5c1-4212-8c91-18f2b7ff85ec")
    assert str(match.id) == "ca19c433-a5c1-4212-8c91-18f2b7ff85ec"

    stats = await match.get_stats()
    assert len(stats.players) == 8

    info = await match.get_info()
    assert round(info.duration.seconds) == (9 * 60 + 27)

    map_ = await match.get_map()
    assert map_.public_name == "Argyle"

    mode = await match.get_mode()
    assert mode.public_name == "Ranked:CTF 3 Captures"

    playlist = await match.get_playlist()
    assert playlist is not None
    assert playlist.public_name == "Ranked Arena"

    map_mode_pair = await match.get_map_mode_pair()
    assert map_mode_pair is not None
    assert map_mode_pair.public_name == "Ranked:CTF 3 Captures on Argyle"

    skill = await match.get_skill()
    assert skill is not None
    assert skill.value[0].result.team_mmrs == {
        0: 962.623065450361,
        1: 975.6512043496726,
    }

    users = await match.get_users()
    assert "xuid(2535445291321133)" in users
acurtis166 commented 10 months ago

I don't think this is useful enough to warrant addition. I think something with batch efficiency and automatic retrieval of match data might be better.

aapokaapo commented 10 months ago

Sorry, I've been on vacation for past week and won't be home before 1/2/2024. In it's current form this doesn't much differ from just fetching MatchStats, MatchSkills, gamemode and map yourself with HaloClient