|
5 | 5 | #pylint: disable=undefined-variable |
6 | 6 | """ Demonstrate doing a batch request with a dependency on another request """ |
7 | 7 |
|
8 | | -graph_client = GraphServiceClient(credentials=token, scopes=graph_scopes) |
9 | | -# Use the request builder to generate a regular |
10 | | -# request to /me |
11 | | -user_request = graph_client.me.to_get_request_information() |
12 | | - |
13 | | -today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) |
14 | | -tomorrow = today + timedelta(days=1) |
15 | | - |
16 | | -new_event = Event( |
17 | | - subject="File end-of-day report", |
18 | | - start=DateTimeTimeZone( |
19 | | - date_time=(today + timedelta(hours=17)).isoformat(timespec='seconds'), |
20 | | - time_zone='Pacific Standard Time' |
21 | | - ), |
22 | | - end=DateTimeTimeZone( |
23 | | - date_time=(today + timedelta(hours=17, minutes=30)).isoformat(timespec='seconds'), |
24 | | - time_zone='Pacific Standard Time' |
25 | | - ) |
26 | | -) |
27 | | - |
28 | | -# Use the request builder to generate a regular |
29 | | -add_event_request = graph_client.me.events.to_post_request_information(new_event) |
30 | | - |
31 | | -# Use the request builder to generate a regular |
32 | | -# request to /me/calendarview?startDateTime="start"&endDateTime="end" |
33 | | -query_params = CalendarViewRequestBuilder.CalendarViewRequestBuilderGetQueryParameters( |
34 | | - start_date_time=today.isoformat(timespec='seconds'), |
35 | | - end_date_time=tomorrow.isoformat(timespec='seconds') |
36 | | -) |
37 | | - |
38 | | -config = CalendarViewRequestBuilder.CalendarViewRequestBuilderGetRequestConfiguration( |
39 | | - query_parameters=query_params |
40 | | -) |
41 | | -events_request = graph_client.me.calendar_view.to_get_request_information(config) |
42 | | - |
43 | | -# Build the batch |
44 | | -add_event_batch_item = BatchRequestItem(request_information=add_event_request) |
45 | | -add_event_batch_item.body = { |
46 | | - "@odata.type": "#microsoft.graph.event", |
47 | | - "end": { |
48 | | - "dateTime": "2024-10-14T17:30:00", |
49 | | - "timeZone": "Pacific Standard Time" |
50 | | - }, |
51 | | - "start": { |
52 | | - "dateTime": "2024-10-14T17:00:00", |
53 | | - "timeZone": "Pacific Standard Time" |
54 | | - }, |
55 | | - "subject": "File end-of-day report" |
56 | | -} |
57 | | -add_event_batch_item.body = json.dumps(add_event_batch_item.body) |
58 | | - |
59 | | -print(f"Event to be added {type(add_event_batch_item.body)}") |
60 | | - |
61 | | -events_batch_item = BatchRequestItem(request_information=events_request) |
62 | | - |
63 | 8 | update_profile_pic_request = RequestInformation() |
64 | 9 | update_profile_pic_request.http_method = "PUT" |
65 | 10 | update_profile_pic_request.url = "/me/photo/$value" |
66 | 11 | update_profile_pic_request.headers = RequestHeaders() |
67 | 12 | update_profile_pic_request.headers.add("Content-Type", "image/jpeg") |
68 | 13 | current_directory = os.path.dirname(os.path.abspath(__file__)) |
69 | | -image_file_path = os.path.join(current_directory, "app_headshot.jpeg") |
| 14 | +image_file_path = os.path.join(current_directory, "my_cool_pic.jpeg") |
70 | 15 |
|
71 | 16 | with open(image_file_path, 'rb') as image_file: |
72 | | - # base64_image = base64.b64encode(image_file.read()).decode('utf-8') |
73 | 17 | base64_image = base64.b64encode(image_file.read()).decode('ascii') |
74 | 18 |
|
75 | 19 | update_profile_pic_request.content = base64_image |
76 | | -# output_file_path = os.path.join(current_directory, "app_image_bytes.txt") |
77 | 20 |
|
78 | | -print(f"Image content {type(update_profile_pic_request.content)}") |
79 | 21 | # body has a bytes array |
80 | 22 | update_profile_photo_batch_item = BatchRequestItem(request_information=update_profile_pic_request) |
81 | 23 | print(f"batch with image {type(update_profile_photo_batch_item.body)}") |
|
0 commit comments