From a571d929a3d082005c48476055a4cd4663a85a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Ob=C5=AFrka?= Date: Sun, 28 Feb 2016 20:24:38 +0100 Subject: Make refactoring of assign_to_person to common reusable code --- todoist | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/todoist b/todoist index 92867d5..cd469c3 100755 --- a/todoist +++ b/todoist @@ -92,16 +92,16 @@ def build_collaborators_list(data): collaborators = { col["full_name"].lower(): col["id"] for col in data["Collaborators"] } return collaborators -def assign_to_person(name, collaborators): +def find_candidate(name, storage): candidates = [] - for k, v in collaborators.items(): + for k, v in storage.items(): if k.find(name) != -1: candidates.append((k, v)) if len(candidates) == 0: return None, "No candidate found" elif len(candidates) > 1: clist = [ item[0] for item in candidates ] - clist.insert(0, "Multiple candidates found. Make better specification of one of them:") + clist.insert(0, "Multiple candidates found. Pick one of them:") return None, "\n".join(clist) else: return candidates[0][1], None @@ -164,9 +164,9 @@ def main(): ## Assign to person if args.assign: - aid, err = assign_to_person(args.assign.lower(), collaborators) + aid, err = find_candidate(args.assign.lower(), collaborators) if not aid: - print(err, file=sys.stderr) + print("Assign to person error:", err, file=sys.stderr) sys.exit(1) kwargs["responsible_uid"] = aid -- cgit v1.2.3