Skip to content

Commit 2e9c09e

Browse files
shemogumbebaywet
authored andcommitted
update samples
1 parent ac6b985 commit 2e9c09e

File tree

1 file changed

+1
-59
lines changed

1 file changed

+1
-59
lines changed

samples/batch_requests/batch_body_with_bytes_content.py

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,19 @@
55
#pylint: disable=undefined-variable
66
""" Demonstrate doing a batch request with a dependency on another request """
77

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-
638
update_profile_pic_request = RequestInformation()
649
update_profile_pic_request.http_method = "PUT"
6510
update_profile_pic_request.url = "/me/photo/$value"
6611
update_profile_pic_request.headers = RequestHeaders()
6712
update_profile_pic_request.headers.add("Content-Type", "image/jpeg")
6813
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")
7015

7116
with open(image_file_path, 'rb') as image_file:
72-
# base64_image = base64.b64encode(image_file.read()).decode('utf-8')
7317
base64_image = base64.b64encode(image_file.read()).decode('ascii')
7418

7519
update_profile_pic_request.content = base64_image
76-
# output_file_path = os.path.join(current_directory, "app_image_bytes.txt")
7720

78-
print(f"Image content {type(update_profile_pic_request.content)}")
7921
# body has a bytes array
8022
update_profile_photo_batch_item = BatchRequestItem(request_information=update_profile_pic_request)
8123
print(f"batch with image {type(update_profile_photo_batch_item.body)}")

0 commit comments

Comments
 (0)