def puppet_kick(node_list): # thread pool pkick = Pkick() poolsize = 20 pool = threadpool.ThreadPool(poolsize) requests = threadpool.makeRequests(pkick.kick, node_list, enqueue) [pool.putRequest(req) for req in requests] pool.wait() CacheHandler.write(RESULT_CACHE, json.dumps(RESULT_Q))
def get_all_node(self): if os.path.exists(NODE_CACHE): tidy_node_list = CacheHandler.unserialize(NODE_CACHE) else: tidy_node_list = self.update_node_cache() return tidy_node_list
def get_previous_node(self, succ=True, append_err=True): """ get previous nodes who were kicked successfully or failed Args: succ: if True return nodes who is kicked successfully if False return nodes who is kicked failed """ result_cache = CacheHandler.unserialize(RESULT_CACHE) nodes = [] for result in result_cache: # each element is [host, stdout, stderr, status] host = result[0] err = result[2] if succ: if result[3]: nodes.append(host) else: if not result[3]: if append_err: nodes.append([host,err]) else: nodes.append(host) return nodes
def update_node_cache(self): tidy_node_list = self.get_node_list_from_puppet() CacheHandler.serialize(NODE_CACHE, tidy_node_list) return tidy_node_list
import clashapi from cachehandler import CacheHandler token = """ """.replace("\n", "") scheme = "https" server = "api.clashofclans.com/v1" base_url = scheme + "://" + server clan_id = "#9Y00CGGV".replace("#", "%23") clashapi.set_user_agent("clashapi.py/0.9") api = clashapi.EVEAPIConnection(url=base_url, cacheHandler=CacheHandler()) auth = api.auth(token=token) # result = auth.clans(name="le Nakano") # result = auth.clan(clan_id)() # result = auth.clan(clan_id).members() # result = auth.locations() # result = auth.location("32000087")() # result = auth.location("32000087").rankings.players() result = auth.leagues() print(result)