コード例 #1
0
ファイル: regioncardpop.py プロジェクト: HN67/nsapi
def check_region(requester: nsapi.NSRequester,
                 region: str,
                 previous: Container[str] = None) -> Sequence[str]:
    """Checks all nations in the specified region for trading card activity.
    Makes at most 1 + region population requests (1 for each nation).
    A nation does not qualify if it is in the `previous` container.
    """
    # If a previous list is not provided, use an empty set
    if not previous:
        previous = set()

    participants = []

    # Grabs all residents of the region
    residents = requester.region(region).shard("nations").split(":")

    # Make a request for each resident
    for nation in residents:
        if nation not in previous:
            info = requester.nation(nation).deck_info()
            # Save the nation if it meets any of the requirments
            if (info.numCards > 0 or info.bank > 0 or info.lastValued
                    or info.lastPackOpened):
                participants.append(nation)

    return participants
コード例 #2
0
def unendorsed_nations_v2(
    requester: nsapi.NSRequester, endorser: str
) -> Tuple[str, Iterable[str]]:
    """Finds all WA members of the nation's region who have not been endorsed
    Returns a tuple containing the region, and a iterable of unendorsed nations
    """

    # Retrieve endorser region and endorsement list
    logging.info("Collecting WA Members")
    info = requester.nation(endorser).shards("region", "endorsements")
    region = info["region"]
    endorsements = set(info["endorsements"].split(","))

    # Retrieve regional citizens by cross referencing residents and wa members
    citizens = set(requester.wa().shard("members").split(",")) & set(
        requester.region(region).shard("nations").split(":")
    )

    # Optionally only check nations who havent endorsed the endorser
    nations = citizens - endorsements

    # Check each nation's endorsments
    logging.info("Checking WA members for endorsement")
    nonendorsed = [
        nation
        for nation in nations
        if endorser not in requester.nation(nation).shard("endorsements")
    ]

    return (region, nonendorsed)
コード例 #3
0
ファイル: endotarter.py プロジェクト: swordrager/nsapi
def collect(requester: nsapi.NSRequester,
            region: str) -> t.Mapping[str, t.Iterable[str]]:
    """Compiles the endorsees of every WA nation in the region."""

    # Cross-reference region nations and WA members
    region_nations = set(requester.region(region).nations())
    wa_nations = set(requester.wa().shard("members").split(","))
    members = region_nations & wa_nations

    # A dict mapping each WA member of this region to the nations they endorse
    endorsees: t.Dict[str, t.List[str]] = {member: [] for member in members}

    # Parse nation dump
    for nation in requester.dumpManager().nations():
        # Search for nations that are WA in this region
        if nation in members:
            for endorser in nation.endorsements:
                endorsees[endorser].append(nation.name)

    return endorsees
コード例 #4
0
ファイル: waresidents.py プロジェクト: swordrager/nsapi
def residents(requester: nsapi.NSRequester, region: str) -> Collection[str]:
    """Retrieves the WA residents of the given region."""

    # Retrieve residents
    return set(requester.region(region).nations()) & set(
        requester.wa().shard("members").split(","))