-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
74 lines (55 loc) · 2.19 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""M365 Developer | Microsoft Graph Python SDK and Semantic Kernel"""
import asyncio
import semantic_kernel as sk
from azure.identity.aio import EnvironmentCredential
from kiota_authentication_azure.azure_identity_authentication_provider import AzureIdentityAuthenticationProvider
from kiota_abstractions.api_error import APIError
from msgraph import GraphRequestAdapter
from msgraph import GraphServiceClient
from msgraph.generated.models.todo_task_list import TodoTaskList
from msgraph.generated.models.todo_task import TodoTask
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
kernel = sk.Kernel()
# Create auth proviver object. Used to authenticate request
credential = EnvironmentCredential()
scopes = ['https://graph.microsoft.com/.default']
# Get a service client
client = GraphServiceClient(credential, scopes)
# GET emails from user
async def get_user_messages():
"""Getting the messages of a user"""
try:
messages = await client.users.by_user_id("[email protected]").messages.get()
# for msg in messages.value:
# print(
# msg.subject,
# msg.id,
# )
except APIError as e_rr:
print(f'Error: {e_rr.error.message}')
# Create ToDo list
my_list_id = "_"
my_action_items = [
"Create email",
"Review presentation",
"Schedule meeting"
]
async def create_todo_list_and_tasks():
"""Create a ToDo list"""
try:
request_body = TodoTaskList()
request_body.display_name = 'Action items from emails'
result = await client.users.by_user_id("[email protected]").todo.lists.post(request_body)
my_list_id = result.id
# print(my_list_id)
# Adding tasks
for item in my_action_items:
request_body = TodoTask()
request_body.title = item
result = await client.users.by_user_id("[email protected]").todo.lists.by_todo_task_list_id(my_list_id).tasks.post(request_body)
except APIError as e_rr:
print(f'Error: {e_rr.error.message}')
async def main():
await get_user_messages()
await create_todo_list_and_tasks()
asyncio.run(main())