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 paged_get_lazy(url, params, session, total_count=None, page_size=250):
    """
    Combine paged URL responses; returns a generator
    """
    if total_count is not None and total_count < page_size:
        page_size = total_count

    params["count"] = page_size
    while True:
        out = check_network_response(session.get(url, params=params))
        if "items" in out:
            d = out["items"]
        else:
            d = out.get("data", [])
        page = out.get("nextPage")

        yield from d
        if page is None or len(d) == 0 or len(d) < page_size:
            break

        if total_count is not None:
            total_count -= len(d)
            if total_count <= 0:
                break
            if total_count < page_size:
                page_size = total_count
                params["count"] = page_size

        params["page"] = page
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_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.º 6
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.º 7
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.º 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_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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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.º 18
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.º 19
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.º 20
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.º 21
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.º 22
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.º 23
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.º 24
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.º 25
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.º 26
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)
Exemplo n.º 27
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.º 28
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.º 29
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.º 30
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)