Exemplo n.º 1
0
def search(cache_time=5, limit=100, query={}):
    """
    Search through feed events.
    Set to limit -1 to get everything.
    Returns a generator that only gets the following page when needed.
    Possible parameters for query: https://alisww.github.io/eventually/#/default/events
    """
    s = session(cache_time)

    res_len = 0

    while limit == -1 or res_len < limit:
        out = check_network_response(
            s.get(f"{BASE_URL}/events",
                  params={
                      'offset': res_len,
                      'limit': 100,
                      **query
                  }))
        out_len = len(out)
        if out_len < 100:
            yield from out
            break
        else:
            res_len += out_len
            yield from out
Exemplo n.º 2
0
def get_entities(type_,
                 id_=None,
                 at=None,
                 count=None,
                 page_size=1000,
                 cache_time=5):
    """
    Chronicler V2 Entities endpoint

    Args:
        type_: type of entity to filter by (player, team, etc)
        id_: id or list of ids to filter type by
        at: return entities at this timestamp (ISO string or python `datetime`)
        count: number of entries to return.
        page_size: number of elements to get per-page
        cache_time: response cache lifetime in seconds, or `None` for infinite cache

    Returns:
        generator of all entities of a certain type at one point in time

    """
    if isinstance(at, datetime):
        at = at.strftime(TIMESTAMP_FORMAT)

    params = {"type": type_}
    if id_:
        params["id"] = prepare_id(id_)
    if at:
        params["at"] = at
    if count:
        params["count"] = count

    s = session(cache_time)
    if page_size:
        if page_size < 1 or page_size > 1000:
            raise ValueError("page_size must be between 1 and 1000")
        params["count"] = page_size

    s = session(cache_time)
    return paged_get(f'{BASE_URL_V2}/entities',
                     params=params,
                     session=s,
                     total_count=count,
                     page_size=page_size,
                     lazy=True)
Exemplo n.º 3
0
def get_player_names(*, cache_time=5):
    """
    Get all player names

    Args:
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    return check_network_response(s.get(f'{BASE_URL}/players/names'))
Exemplo n.º 4
0
def get_teams(*, cache_time=5):
    """
    Get all Teams

    Args:
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    return check_network_response(s.get(f'{BASE_URL}/teams')).get("data", [])
Exemplo n.º 5
0
def get_offseason_election_details(*, cache_time=5):
    """
    Get current Election ballot.

    Args:
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/offseasonSetup')
    return check_network_response(res)
Exemplo n.º 6
0
def get_simulation_data(*, cache_time=5):
    """
    Get current simulation state

    Args:
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/simulationData')
    return check_network_response(res)
Exemplo n.º 7
0
def get_global_events(*, cache_time=5):
    """
    Get Current Global Events (Ticker Text).

    Args:
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/globalEvents')
    return check_network_response(res)
Exemplo n.º 8
0
def get_days_since_incineration(*, cache_time=5):
    """
    Get the timestamp of the most recent incineration

    Args:
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/api/daysSinceLastIncineration')
    return check_network_response(res)
Exemplo n.º 9
0
def get_tributes(*, cache_time=5):
    """
    Get current Hall of Flame

    Args:
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/api/getTribute')
    return check_network_response(res)
Exemplo n.º 10
0
def get_gift_progress(*, cache_time=5):
    """
    Get league-wide gift shop progress

    Args:
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/giftProgress')
    return check_network_response(res)
Exemplo n.º 11
0
def get_all_teams(*, cache_time=5):
    """
    Get All Teams, including Tournament teams and Hall Stars. Returns dictionary keyed by team ID.

    Args:
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/allTeams')
    return {t['id']: t for t in check_network_response(res)}
Exemplo n.º 12
0
def get_all_divisions(*, cache_time=5):
    """
    Get list of all divisions, including removed divisions. Returns dictionary keyed by division ID.

    Args:
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/allDivisions')
    return {d['id']: d for d in check_network_response(res)}
Exemplo n.º 13
0
def get_all_players(*, cache_time=5):
    """
    Get list of player names and IDs

    Args:
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/playerNamesIds')
    return check_network_response(res)
Exemplo n.º 14
0
def get_season_day_count(season, cache_time=5):
    """
    Get number of days in a season, by season

    Args:
        season: season, 1 indexed
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/seasondaycount?season={season - 1}')
    return check_network_response(res)
Exemplo n.º 15
0
def get_renovation_progress(id_, cache_time=5):
    """
    Get stadium renovation progress by stadium ID

    Args:
        id_: stadium ID
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/renovationProgress?id={id_}')
    return check_network_response(res)
Exemplo n.º 16
0
def get_feed_story(id_, cache_time=5):
    """
    Get Feed story item by ID

    Args:
        id_: Event ID
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/feed/story?id={id_}')
    return check_network_response(res)
Exemplo n.º 17
0
def get_playoff_round(id_, cache_time=5):
    """
    Get playoff round by ID

    Args:
        id_: playoff round ID
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/playoffRound?id={id_}')
    return check_network_response(res)
Exemplo n.º 18
0
def get_old_items(ids=None):
    s = session(None)
    res = s.get(
        "https://raw.githubusercontent.com/xSke/blaseball-site-files/d111b4a5742b9e7c15a8592fca3f09d9134ff8d5/data/items.json"
    )
    data = check_network_response(res)
    if isinstance(ids, list):
        data = list(filter(lambda x: x['id'] in ids, data))
        if len(data) == 0:
            data = [{"id": "????", "name": "????", "attr": "NONE"}] * len(ids)
    return data
Exemplo n.º 19
0
def get_tiebreakers(id, cache_time=5):
    """
    Get tiebreakers (Divine Favor) by ID

    Args:
        id_: tiebreaker ID
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/tiebreakers?id={id}')
    return {g['id']: g for g in check_network_response(res)}
Exemplo n.º 20
0
def get_season(season_number, cache_time=5):
    """
    Get season info by season number

    Args:
        season_number: season, 1 indexed
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/season?number={season_number - 1}')
    return check_network_response(res)
Exemplo n.º 21
0
def get_standings(id_, cache_time=5):
    """
    Get league standings by ID

    Args:
        id_: standings ID
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/standings?id={id_}')
    return check_network_response(res)
Exemplo n.º 22
0
def get_team_election_stats(team_id, cache_time=5):
    """
    Get will contribution percentage by team ID

    Args:
        team_id: team ID
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/teamElectionStats?id={team_id}')
    return check_network_response(res)
Exemplo n.º 23
0
def get_players_by_item(item, cache_time=5):
    """
    Get player holding an item

    Args:
        item: item ID
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/playersByItemId?id={item}')
    return check_network_response(res)
Exemplo n.º 24
0
def get_offseason_recap(season, cache_time=5):
    """
    Get Election results by season.

    Args:
        season: Season, 1 indexed
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/offseasonRecap?season={season - 1}')
    return check_network_response(res)
Exemplo n.º 25
0
def get_game_by_id(id_, cache_time=5):
    """
    Get game by ID.

    Args:
        id_: game ID
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/gameById/{id_}')
    return check_network_response(res)
Exemplo n.º 26
0
def get_league(id_='d8545021-e9fc-48a3-af74-48685950a183', cache_time=5):
    """
    Get league by ID.

    Args:
        id_: league ID, defaults to current league (Internet League Blaseball)
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/league?id={id_}')
    return check_network_response(res)
Exemplo n.º 27
0
def get_team(id_, cache_time=5):
    """
    Get team by ID.

    Args:
        id_: team ID
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/team?id={id_}')
    return check_network_response(res)
Exemplo n.º 28
0
def get_subleague(id_, cache_time=5):
    """
    Get subleague by ID (eg: Mild, Evil, etc).

    Args:
        id_: subleague ID
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/subleague?id={id_}')
    return check_network_response(res)
Exemplo n.º 29
0
def get_weather(*, cache_time=5):
    """
    Get weather by ID

    Args:
        ids: weather ID(s). Can be a single string ID, comma separated string, or list.
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_GITHUB}/weather.json')
    return check_network_response(res)
Exemplo n.º 30
0
def get_playoff_details(season, cache_time=5):
    """
    Get playoff information by season.

    Args:
        season: season, 1 indexed.
        cache_time: response cache lifetime in seconds, or `None` for infinite cache
    """
    s = session(cache_time)
    res = s.get(f'{BASE_URL}/database/playoffs?number={season - 1}')
    return check_network_response(res)