aboutsummaryrefslogtreecommitdiffstats
path: root/todoist
diff options
context:
space:
mode:
authorGravatar Robin Obůrka <r.oburka@gmail.com> 2016-02-27 00:01:35 +0100
committerGravatar Robin Obůrka <r.oburka@gmail.com> 2016-02-27 00:01:35 +0100
commit66f2b318f2369bb5462800f6c58a029307ac2d07 (patch)
tree88ca5b17115484662f3f04e30f4fce08d5712a59 /todoist
parentAdd licence info (diff)
downloadtodoist-66f2b318f2369bb5462800f6c58a029307ac2d07.tar.xz
Make "assign to person" process more careful
Diffstat (limited to 'todoist')
-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