aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robin Obůrka <r.oburka@gmail.com> 2016-02-25 21:19:31 +0100
committerGravatar Robin Obůrka <r.oburka@gmail.com> 2016-02-25 21:19:31 +0100
commitb6e5978d0146db7f35b2bffea58bc87080bdfb5c (patch)
tree8274bcb4597828f360547033272df0ef6cbb6f99
parentAdd argument --get-token (diff)
downloadtodoist-b6e5978d0146db7f35b2bffea58bc87080bdfb5c.tar.xz
Provide assign function
-rwxr-xr-xtodoist26
1 files changed, 24 insertions, 2 deletions
diff --git a/todoist b/todoist
index 66c42ab..f40e27a 100755
--- a/todoist
+++ b/todoist
@@ -32,6 +32,10 @@ def arg_parser():
help="Severity (or priority) of task",
type=int,
choices=[1, 2, 3, 4])
+ parser.add_argument("-a", "--assign",
+ metavar="NAME",
+ help="Assign to collaborator",
+ type=str)
parser.add_argument("-d", "--date",
metavar="DATE",
help="Date string",
@@ -64,6 +68,10 @@ def build_project_list(data):
projects = { proj["name"].lower(): proj["id"] for proj in data["Projects"] }
return projects
+def build_collaborators_list(data):
+ collaborators = { col["full_name"].lower(): col["id"] for col in data["Collaborators"] }
+ return collaborators
+
def main():
args = arg_parser()
@@ -94,6 +102,7 @@ def main():
sys.exit(0)
projects = build_project_list(data)
+ collaborators = build_collaborators_list(data)
## Prepare data
if not args.msg:
@@ -105,14 +114,27 @@ def main():
kwargs = {}
kwargs["date_string"] = args.date
if args.project:
- if args.project in projects:
- kwargs["project_id"] = projects[args.project]
+ proj = args.project.lower()
+ if proj in projects:
+ kwargs["project_id"] = projects[proj]
else:
print("WARNING: Unknown project. Task will be stored in Inbox", file=sys.stderr)
if args.severity:
kwargs["priority"] = args.severity
+ if args.assign:
+ name = args.assign.lower()
+ aid = None
+ for k, v in collaborators.items():
+ if k.find(name) != -1:
+ aid = v
+ break
+ if not aid:
+ print("ERROR: Unknown person", file=sys.stderr)
+ sys.exit(1)
+ kwargs["responsible_uid"] = aid
+
## Store task
status = api.add_item(msg, **kwargs)
if "error" in status: