diff options
author | Robin Obůrka <r.oburka@gmail.com> | 2016-02-27 00:01:35 +0100 |
---|---|---|
committer | Robin Obůrka <r.oburka@gmail.com> | 2016-02-27 00:01:35 +0100 |
commit | 66f2b318f2369bb5462800f6c58a029307ac2d07 (patch) | |
tree | 88ca5b17115484662f3f04e30f4fce08d5712a59 | |
parent | Add licence info (diff) | |
download | todoist-66f2b318f2369bb5462800f6c58a029307ac2d07.tar.xz |
Make "assign to person" process more careful
-rwxr-xr-x | todoist | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -92,6 +92,20 @@ 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): + candidates = [] + for k, v in collaborators.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:") + return None, "\n".join(clist) + else: + return candidates[0][1], None + def main(): args = arg_parser() @@ -150,14 +164,9 @@ def main(): ## Assign to person if args.assign: - name = args.assign.lower() - aid = None - for k, v in collaborators.items(): - if k.find(name) != -1: - aid = v - break + aid, err = assign_to_person(args.assign.lower(), collaborators) if not aid: - print("ERROR: Unknown person", file=sys.stderr) + print(err, file=sys.stderr) sys.exit(1) kwargs["responsible_uid"] = aid |