async def test_stream_data():
    async for event in stream_events(url='http://localhost:8080/streamData'):
        payload = StreamData(event)
        print(payload)
        schedule = {id: g for id, g in payload.games.schedule.games.items()}
        print(schedule)
        print(payload.leagues.teams)
Exemple #2
0
 async def stream(self, url='https://www.blaseball.com/events/streamData'):
     async for event in stream_events(url=url):
         if not event:
             continue
         stream_data = StreamData(event)
         self.update(stream_data.games,
                     raw=event,
                     fights=stream_data.fights)
Exemple #3
0
async def test_stream():
    async for event in stream_events():
        payload = event
        print(payload)
        schedule = {
            g['id']: Game(g) for g in payload.get('games', {}).get('schedule')
        }
        print(schedule)
Exemple #4
0
async def test_stream_data():
    async for event in stream_events(url='http://api-test.sibr.dev/replay/v1/replay?from=2020-10-07T13:02:00Z'):
        payload = StreamData(event)
        print(payload)
        schedule = {
            id: g for id, g in payload.games.schedule.games.items()
        }
        print(schedule)
        print(payload.leagues.teams)
Exemple #5
0
async def main() -> None:
    leagues = None
    with Live(display.layout, auto_refresh=False) as live:
        async for event in stream_events():
            stream_data = StreamData.parse_obj(event)

            if stream_data.leagues:
                leagues = stream_data.leagues

            if (games := stream_data.games) and leagues is not None:
                if games.sim.day < 99:
                    game_data = season.get_standings(games, leagues)
                    display.update_standings(game_data, games.sim)
                else:
                    postseason_data = postseason.get_playoffs(games, leagues)
                    display.update_postseason(postseason_data)

            live.refresh()
Exemple #6
0
async def main() -> None:
    phase_progress = Progress(
        "[progress.description]{task.description}",
        BarColumn(),
        "[progress.percentage]{task.percentage:>3.0f}%",
        expand=True,
    )
    phase = phase_progress.add_task("Phase")
    league_progress = Progress(
        "[progress.description]{task.description}",
        BarColumn(),
        "[progress.percentage]{task.completed:g}/{task.total}",
        expand=True,
    )
    chest = league_progress.add_task("Community Chest", total=3000)
    sunsun = league_progress.add_task("Sun(Sun)")
    layout = Layout()
    layout.split(
        Layout(name="phase", size=1),
        Layout(name="highlight"),
        Layout(name="games"),
        Layout(name="progress", size=2),
    )
    layout["phase"].update(phase_progress)
    layout["games"].update(Text())
    layout["progress"].update(league_progress)

    leagues = None
    with Live(layout, auto_refresh=False) as live:
        async for event in stream_events():
            stream_data = StreamData.parse_obj(event)

            if stream_data.leagues:
                leagues = stream_data.leagues
                chest_stats = leagues.stats.community_chest
                league_progress.update(chest, completed=chest_stats.runs)
                sun_stats = leagues.stats.sunsun
                league_progress.update(sunsun,
                                       completed=sun_stats.current,
                                       total=sun_stats.maximum)
            if leagues is None:
                continue

            if games := stream_data.games:
                phase_name, completed, total = phase_time(games.sim)
                phase_progress.update(
                    phase,
                    description=f"{phase_name} Day {games.sim.day + 1}",
                    completed=completed,
                    total=total,
                )

                today = sorted(
                    games.schedule,
                    key=lambda x: x.home_odds * x.away_odds + x.game_complete,
                )
                try:
                    favored = get_team_game(TEAM, today)
                    # Reposition followed team to the front
                    today.remove(favored)
                    today.insert(0, favored)
                except ValueError:
                    pass
                tomorrow = sorted(
                    games.tomorrow_schedule,
                    key=lambda x: x.home_odds * x.away_odds + x.game_complete,
                )
                try:
                    favored = get_team_game(TEAM, tomorrow)
                    # Reposition followed team to the front
                    tomorrow.remove(favored)
                    tomorrow.insert(0, favored)
                except ValueError:
                    pass

                game_widgets = render_games(today, leagues.stadiums)
                try:
                    forecast = little_game(tomorrow[0])
                    layout["highlight"].update(
                        Columns((next(game_widgets), forecast), expand=True))
                except IndexError:
                    layout["highlight"].update(next(game_widgets))
                layout["games"].update(
                    Columns(game_widgets, equal=True, expand=True))

            live.refresh()