Created
September 30, 2023 11:56
-
-
Save stalinwesley/818409e6637e4cf93ec7b318d091e63b to your computer and use it in GitHub Desktop.
google_calendar.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from google.oauth2 import service_account | |
from googleapiclient.discovery import build | |
from datetime import datetime | |
current_datetime = datetime.now() | |
# Set the service account credentials file path | |
credentials_file = 'token.json' | |
# Set the calendar ID (usually your email address) | |
calendar_id = 'primary' | |
# Set up the scopes | |
scopes = ['https://www.googleapis.com/auth/calendar.events'] | |
def create_event(): | |
credentials = service_account.Credentials.from_service_account_file( | |
credentials_file, scopes=scopes) | |
service = build('calendar', 'v3', credentials=credentials) | |
# Refer to the Python quickstart on how to setup the environment: | |
# https://developers.google.com/calendar/quickstart/python | |
# Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any | |
# stored credentials. | |
event = { | |
'summary': 'Stalin'+current_datetime, | |
'location': '800 Howard St., San Francisco, CA 94103', | |
'description': 'A chance to hear more about Google\'s developer products.', | |
'start': { | |
'dateTime': '2023-09-30T09:00:00-05:30', | |
'timeZone': 'Asia/Kolkata', | |
}, | |
'end': { | |
'dateTime': '2023-09-30T09:10:00-05:30', | |
'timeZone': 'Asia/Kolkata', | |
}, | |
'recurrence': [ | |
'RRULE:FREQ=DAILY;COUNT=2' | |
], | |
'attendees': [ | |
{'email': '[email protected]'}, | |
{'email': '[email protected]'}, | |
], | |
'reminders': { | |
'useDefault': False, | |
'overrides': [ | |
{'method': 'email', 'minutes': 2}, | |
{'method': 'popup', 'minutes': 2}, | |
], | |
}, | |
} | |
event = service.events().insert(calendarId='primary', body=event).execute() | |
print ('Event created: %s' % (event.get('htmlLink'))) | |
if __name__ == '__main__': | |
create_event() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment