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)
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
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(","))