forked from vgrem/office365-rest-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_task.py
More file actions
22 lines (18 loc) · 752 Bytes
/
create_task.py
File metadata and controls
22 lines (18 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from examples import acquire_token_by_username_password
from office365.graph_client import GraphClient
from office365.planner.plans.plan import PlannerPlan
def ensure_plan(planner, name):
"""
:type planner: office365.planner.user.PlannerUser
:type name: str
:rtype: PlannerPlan
"""
plans = planner.plans.get().filter("title eq '{0}'".format(name)).execute_query()
if len(plans) > 0:
return plans[0]
else:
return planner.plans.add(title=name).execute_query()
client = GraphClient(acquire_token_by_username_password)
plan = ensure_plan(client.me.planner, "My plan")
task = client.planner.tasks.add(title="New task", planId=plan.id).execute_query()
print("Task {0} has been created".format(task.title))