From f61ba4079d30647bd0f7aa00c590def6d563573c Mon Sep 17 00:00:00 2001 From: Modrzew Date: Wed, 17 Aug 2016 23:10:39 +0200 Subject: [PATCH] Don't use accounts for disabled workers --- utils.py | 18 ++++++++++++++++++ worker.py | 5 +++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index 6d30b1f952..8eb62137d0 100644 --- a/utils.py +++ b/utils.py @@ -113,3 +113,21 @@ def sort_points_for_worker(points, worker_no): def get_distance(p1, p2): return math.sqrt(pow(p1[0] - p2[0], 2) + pow(p1[1] - p2[1], 2)) + + +def get_worker_account(worker_no): + """Returns appropriate ACCOUNT entry for worker + + Omits disabled workers. + """ + # This should never happen, but better be safe! + if worker_no in config.DISABLE_WORKERS: + return None, None, None + account_no = 0 + for i in range(worker_no + 1): + if i in config.DISABLE_WORKERS: + continue + if i == worker_no: + return config.ACCOUNTS[account_no] + account_no += 1 + raise ValueError('Workers incompatible with accounts') diff --git a/worker.py b/worker.py index 87c6e00806..9ead7d91eb 100644 --- a/worker.py +++ b/worker.py @@ -97,13 +97,14 @@ def run(self): self.cycle = 1 self.error_code = None + username, password, service = utils.get_worker_account(self.worker_no) service = config.ACCOUNTS[self.worker_no][2] while True: try: loginsuccess = self.api.login( + username=username, + password=password, provider=service, - username=config.ACCOUNTS[self.worker_no][0], - password=config.ACCOUNTS[self.worker_no][1], ) if not loginsuccess: self.error_code = 'LOGIN FAIL'