add update calendar_event
This commit is contained in:
@@ -63,14 +63,24 @@ def get_access_token():
|
||||
|
||||
return result
|
||||
|
||||
def execute_patch_request(token, endpoint, data):
|
||||
return requests.patch(
|
||||
endpoint,
|
||||
json=data,
|
||||
#data=data,
|
||||
headers={'Authorization': 'Bearer ' + token['access_token']},).json()
|
||||
|
||||
def execute_request(token: dict, endpoint:str):
|
||||
def update_calendar_event(token, event_id, data, user_id=USER_ID):
|
||||
endpoint= "https://graph.microsoft.com/v1.0/users/" + user_id + f"/calendar/events/{event_id}"
|
||||
return execute_patch_request(token, endpoint, data)
|
||||
|
||||
def execute_get_request(token: dict, endpoint:str):
|
||||
return requests.get( # Use token to call downstream service
|
||||
endpoint,
|
||||
headers={'Authorization': 'Bearer ' + token['access_token']},).json()
|
||||
|
||||
def execute_user_request(token, endpoint, user_id=USER_ID):
|
||||
return execute_request(token, "https://graph.microsoft.com/v1.0/users/" + user_id + f"/{endpoint}")
|
||||
return execute_get_request(token, "https://graph.microsoft.com/v1.0/users/" + user_id + f"/{endpoint}")
|
||||
|
||||
def get_all_calendar_events():
|
||||
token = get_access_token()
|
||||
@@ -115,6 +125,8 @@ if __name__ == "__main__":
|
||||
parser.add_argument('--show_calendars', help='Show available calendars', action='store_true')
|
||||
parser.add_argument('--show_event_entries', help='Show available event fields', action='store_true')
|
||||
parser.add_argument('--show_events', help='Show available events for selected calendar', action='store_true')
|
||||
parser.add_argument('--update_test_event', help='Execute a patch request for testing', action='store_true')
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -135,11 +147,38 @@ if __name__ == "__main__":
|
||||
print(json.dumps(list(events)[0].keys(), indent=2))
|
||||
|
||||
if args.show_events:
|
||||
print(json.dumps(events, indent=2))
|
||||
#print(json.dumps(events, indent=2))
|
||||
|
||||
convert_datetimes(events)
|
||||
|
||||
print(json.dumps([(e["subject"], e["start"], e["duration"]) for e in events], indent=2))
|
||||
print(json.dumps([(e["subject"], e["start"], e["duration"], e["attendees"], e["id"]) for e in events], indent=2))
|
||||
|
||||
if args.update_test_event:
|
||||
|
||||
data = {
|
||||
"attendees" :
|
||||
[
|
||||
{
|
||||
"type": "required",
|
||||
"status": {
|
||||
"response": "none",
|
||||
"time": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
"emailAddress": {
|
||||
"name": "Simone Profus",
|
||||
"address": "simone.profus@propedal.at"
|
||||
}
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
data["attendees"][0]["emailAddress"]["name"] = "Patrick S."
|
||||
data["attendees"][0]["emailAddress"]["address"] = "struebin.patrick@gmail.com"
|
||||
|
||||
#Test2
|
||||
event_id = "AAMkADY0MDg1MTVjLTg5ZjItNGQxYS04MGQ3LWY2NjJmYjM0YmZhOQBGAAAAAADXD7SdVoWYQI4RYXbBumMEBwAf_ngZxs71RonY3GuLL8TVAADHFw_OAAAf_ngZxs71RonY3GuLL8TVAABLH9QmAAA="
|
||||
ret = update_calendar_event(token, event_id, data)
|
||||
|
||||
print(json.dumps(ret, indent=2))
|
||||
|
||||
print("Done.")
|
||||
Reference in New Issue
Block a user