Google Calendar API in Python | Add, Update, Delete Events

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey how's it going guys welcome to another google calendar api in python tutorial my name is jay in this video we'll learn how to add update and delete google calendar events using google calendar api all right so this is probably the most important topic when you're working with google account api now let's take a look at the google account api documentation and to add an event i'll be using the instant method all right so let's take a look when we use the event insta method we need to provide the calendar id and below are some of the optional parameters so some of the things we can say such as max attendees do you want to send notifications do you want to send i'll attend these updates uh this one i don't use very much by saying you can manage if your events is a recurring event they can i think can supply a version number to that event and oh and this one is a support attachment so you can attach different documents to your event item i'll show you on how to use uh majority of the parameters and the fields and as well as also show you how to attach different files to event item all right so here's the two scopes that we can use when we want to run the instant method and below is the request body object fields and when we provide the request body object we need to provide the start time and end time and this can be either date time or date which i'll show you an example later and below are the optionals fields so here's the attendees field attachment let's talk about attachments real quick currently the google calendar api does not support file attachment and if we want to attach a file or files we need to first of all upload the files to your google drive or my google drive then we need to provide the google drive file link to this attachments that file your our property you can also specify the color id and again i don't use the conference data field very much so i can give you a description on what the conference data field does and here's the event description and as i mentioned before um when we supply the start day and the end day we need to uh specify if we want to use a date if we're going to use a date then it's going to take this date format which is a year and months and day if you want to uh specify a date plus a time then we'll need to use this of rfc 3339 uh formatting oh and if we are going to use datetime format then we need to supply a timezone and some of the uh fields you can probably go to on your own and here's the id field uh location and recurrence and so on throughout this tutorial i'll pick the fields that i think are used for and here's the status field we can have three options we can set to confirm tentative or cancelled in summary of summary is a pretty important one summary is the event title and transparency visibility all right so that's everything i want to cover in terms of the documentation and below are examples for different languages if we go to python so here they give you a very very basic example all right so let's go into our code editor and here's my my code template and here's my account id actually let me go to my calendar real quick i'll be using this chicago events calendar for demonstration so here's my code to generate the google calendar api service object and again this is my chicago event calendar id and we're going to start by creating one single event so this one is going to be create an event and first i want to grab the color profile list i'll name the color profiles object colors now insert the service object dot colors that gets that execute let me run just a select code i'm going to basically run all the lines individually so you can actually understand line by line what each statement is doing right so here i'm going to print the colors object and that'll give us a list of color profiles for either calendar or event and the dictionary key is going to be the color profile id let's start with creating the request body object first i'm going to name this object event request body and we need to provide the start date and the end date let's say i want to set up an event uh for having lunch with my family and let's say i want to set the uh the lunch date on august 1st at 12 p.m so let's go to the api real quick all right so let's look at this example we provide the start and the end dates we can either uh specify the value as date time or date and day is much easier than just one day event but to set event weight dates and time then we need to provide date time property and the form in the daytime formatting is going to be the rfc datetime format now from my from the google module inside this module i wrote a function called convert to rfc datetime and this function will basically simplify the rfc date time formatting step and to use this function i'll insert the function first right so this function has five parameters the first parameter is the year value month's value day value and followed by the hour value and in the minute value and also we need the second value if we need to add the second value the income would go back to the google module and modify the function according to your name right so as i want to uh create an event to set up a family lunch plan with my with my parents i'll insert the the year and it's going to be 2019 and let's do our guest first and for the hour i want to set the lunch at 12 30 p.m inside the stats property we need to specify the time zone instance i moved to taipei from san francisco so for the time zone i'm going to set the time zone to asia taipei and this one most thing we need to do the time is going to be based on gmt time so i'm going to create a variable called our adjustment and because a type a time zone is -8 from gmt so i'm going to set the value to minus a and this will basically fix the hour display but when we create the event so within the convert to rfc daytime function here i'm going to insert i'm going to add the our adjustment and for the end time i'm going to just copy these two lines and paste i want to send my end time to let's do 2pm and it's going to be based on military time so here i'm going to insert 14. and by d5 want to create an event and this is all you need to provide in the request body but since uh when we create event uh there are actually much more information we need to provide so i'm going to continue when we create an event we need to give our event a title so for the summary property and it's going to be the event title i'm going to name this as a family lunch and we can also provide a description for the description i'm going to type having lunch with the parents let me go back to my calendar so when we create a new event so here we have different color profile we can use all right so i'm going to just randomly pick a color profile id and it's going to be color id and i'm going to use color profile number five and for the status now let's go back to the documentation right so if we search for status is right here so for the status property we can provide three values two different values we can provide confirm tentative or cancel i'm going to i'm going to use confirm and for the transparency so transparency meaning that let's go to the description meaning that you want to block the time on your calendar i'm going to use opaque as my transparency value and this is also the default value the next one is visibility invisibility is you want to make your calendar event visible we can set the visibility as public private or default or even confidential i'm going to set that to private so here i'm going to insert private and the other one i think is pretty important is location and here we can use either a coordinate value or a city name or address so here let me just insert a city chicago in noise all right so if you want to uh insert attachment to your event so here i'm going to insert the attachments property and it's going to be a list now let me go to my google drive unless i want to attach my i have this word template and we need to first of all grab the file id uh see so here this should be an option called open in new window because by default in the url it doesn't show the file id so you need to uh use this open a new window function to open the file in a separate window of separate tab and here is the file id and to insert file it's going to be one dictionary of java file so if you need to insert multiple files then you will need to insert multiple dictionary objects in the dictionary object you just need to provide the file url actually i need to provide the full url sorry this is going to be the entire url and same title is optional so if you want to use a different name for your document you can also provide a different title unless i want to name my file implementation letter templar in word doc and that will be the only file that i want to attach my event all right now the next one i sense pretty important is attendees and it's gonna be a list and again it's gonna be one dictionary per person now let's go back to the documentation and this is for attendee not this one should be okay should be this one all right so here's the attendees object data type answer list and just attend these rackers fields so we can provide attend this email display name comment optional so that's indicating whether or not the attendee can have the option to not to attend to an event i'm going to just make this pretty easy i want to insert the attendee display name for the display name i'm going to just type jj common and i enjoy coding in my email actually this one i'm going to just skip but you can provide the attendee email you can sell the knife if the attendees uh well if the if the attendee's uh presence is optional and it's going to be boolean so i'm going to set that to false it's not is optional attendee organizer i'm going to say yes so the value is going to be two and we can also set the response status the response status has multiple values i think right here so we can use one of these four response status value so i'm going to use accept all right the remaining are fields such as creator and this one's gonna be a dictionary organizer and this one's gonna be addition as well and these two are pretty useful in my opinion in the property fields let me search for creator it's missing okay so it's not on the documentation let me take a look creator okay so apparently it's not on the documentation all right so me remove creator and i will just i'll include organizer so organizer okay so it's missing organizers wall which is interesting let me let me go into the advanced resource option with all response body and here in the response are in the resource representation it has organizer and and here's the create and here's the creator so i think on the documentation it's missing some of the uh the information so just put it so i'll grab this to uh json representation and i'll just put it in in the uh in the script and we'll come in this off because it's kind of like a like a note that uh the value that i can provide you know i don't want to include the self property all right so for the response uh object this is all the information i want to provide to my event item and to create an event in the additional prime test we can specify now i'll go to each parameter individually usually when i create an event if i want to set the parameter value i i will create variables to supply the value since it is easier to track the variables as well as if you need to manipulate the value and it's much easier that way all right so the first parameter value is the max attendees and we can set the maximum attendees to let's see i think there's no maximum number okay so i'm going to set the max attendee to five and do we want to send notification i'm going to say yes do we want to send update i'm going to say no actually uh i'm going to send this to none let me take a look so for the send updates parameter we can use these three values oh external only or none and the last one is suppose attachment so if you are going to attach a file to your event or to your other item you must set this value to 2. all right now let's create the event so here i'm going to store the outputs i'm going to name the output as i will insert my service option dot events dot insert oops i missed i press the wrong key right and here i need to insert the seq method and to current event we need to provide the calendar id max attendees send notification syn update supports attachments and the last one is body and the body object is going to be events request body and here i'll print the response object after we create the event now i'm going to select the lines i want to execute so it's going to be from colors so line 17. all the way to uh line 78 let me try and have a typo right so this should be uh so if i if i read the uh message here i got an unexpected keyword argument and this should be uh pearl send notifications and that means uh this also should be pearl all right let me try again uh so i can just run line 69 to line 78 and because everything else uh executed successfully all right so if i run uh this code block and yeah oh should we ask the cube all right let me try again okay so this time uh it's missing attendee email okay so i guess when we provide the attendees property we need to provide the email so email is a required field all right for the email i'm going to just insert my youtube ads learn data analysis. all right so let me run the entire code again okay so this time the line the code executed successfully i know that because uh in the print statement i print all the event information such as attachments attendees color profile and everything else if i go to my calendar and the events on august 1st and here's my event created by my python script all right let's take a look at the uh event real quick let me see if i can go into the event detail so if we click on add event and now it takes us to all the uh detail of the of this uh particular event all right so on the top uh this the induce the date and time of the event and followed by the time zone remember uh found the python script let me scroll to the top i have this out adjustment variable to make sure that when i create an event the display time and the dates will match to my current time zone if i don't include this uh our adjustment variable to adjust the uh to adjust the time then when i create the event the event is going to show my event time was 8 30 pm to 10 30 p.m and here's the uh attachment all right so let's take a look at the description so descriptions right here and here's the attachment from the google drive file and this one is visibility transparency and the color profile on the right we have the attendees uh see and this is the guest permission oh and this one was i forgot to show you so on the top we have uh event reoccurrence uh that one is a little bit tricky so let me show you how the let me show you how to create event recurrence let me go back to the documentation recurrence all right so it's right here the recurrence property is a loss and when we specify an event recurrence we need to use this rfc 5545 format for now don't think too much on the format i'm going to just give you a can i get a template now to uh to use to set the recurrence value so here i'm above our adjustment i'm going to create a list i'm going to name this list recurrence inside this list i'm going to insert this string value rule so based on what is okay based on a list of values i am basically creating a new rule and we need to insert a column and followed by the frequency and we can set that as a yearly daily monthly or quarterly i'll set the event as monthly and here let me remove this closing single quotation and i think all the letters has to be uppercase and we need to insert a semicolon and follow by how many times do you want the event to occur i'm going to set the count value to 2. now in the event request body object and let's insert the recurrence field at the end so the field name should be recurrence we're going to insert the recurrence actually take a look so going to insert the recurrence list object let me go back to my calendar and delete the event that i just created was hit delete okay now i'm going to highlight everything i want to execute so from line 21 all the way to all the way to line 83 all right so if i go back to my calendar and refresh my page and here's my family lunch event and this time when i look at the reoccurrence uh field so here is my event reoccurrence counts one two times and it's happening on monthly basis in are other frequencies you can set you can set us a weekly on a saturday monthly on the first saturday or any other day or yearly on a certain date we learned how to create an event now let's learn how to update an event update and delete an event is going to be much quicker alright so this one's going to be update event and hear me do this i'm going to store the event id to a vehicle called event id and around line 85 now if i print event id and that will gives me the event id value let's say my parents change their mind they don't want to have lunch anymore they want to have dinner so here let me grab my my functions my start dates and end date functions right so let me grab these two uh code blocks and i'll just put it right here i'm going to create two variables soon yeah so the first variable is going to be start uh date time so i don't even need those two right so the first variable is going to be stop datetime and the second variable is going to be end datetime and i want to change the time from 12 30 pm to 6 30 pm and instance we need to uh insert the value oh hour as military time so i need to use 18 uh for 6 p.m and let's do uh 6 to 8 and to change the event title and description so we can use the we can use the response object and we just need to change the dictionary values so for the start date time so we need to change the date time value and we'll do the same for end date time value i want to change the event title so it's going to be family dina and description so i'll just type having family dinner it'll only update this for our properties in here to update event so insert my service object events update inside the update method we need to provide the calendar id and the event id and to update the event information so we need to resupply the body object so it's going to be event request body that execute now if i run line 93 to 102 and if i go back to my calendar let me go back and refresh my page yes my let's see that's weird let me take a look hold on oh i know why uh this should be response not even request body because we are updating an existing event right so that was my mistake let me try again so if i just run this highlighter code and now if i go back to my calendar and here my event is updated to from uh family lunch to family dinner and if i go back to make sure that the dates and time is uh updated as well now my time got updated to 6 30 p.m to 8 30 p.m and the last thing we're going to learn is how to delete an event to delete an event we just need to use the delete method so service dot events dot delete and we need to supply the calendar id and the event id and if i run line 108 and i'll delete my family dinner event and i see my event is now deleted this is everything i want to cover in this video and hopefully you guys found the videos for and as always thank you guys for watching i'll see you guys on the next video
Info
Channel: Jie Jenn
Views: 27,685
Rating: undefined out of 5
Keywords: Google Calendar API, Google Calendar API in Python, Google Calendar API Events, Add Events with Google Calendar API, update Events with Google Calendar API, Delete Events With Google Calendar API
Id: _uHd0ypR5OI
Channel Id: undefined
Length: 33min 4sec (1984 seconds)
Published: Mon Aug 31 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.