aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xtodoist23
1 files changed, 16 insertions, 7 deletions
diff --git a/todoist b/todoist
index dce9194..92867d5 100755
--- a/todoist
+++ b/todoist
@@ -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