-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogle_Calendar.py
More file actions
45 lines (38 loc) · 1.43 KB
/
Google_Calendar.py
File metadata and controls
45 lines (38 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from pprint import pprint
from Google import Create_Service
import datetime
import datefinder
CLIENT_SECRET_FILE = 'client_secret.json'
API_NAME = 'calendar'
API_VERSION = 'v3'
scopes = ['https://www.googleapis.com/auth/calendar']
service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, scopes)
def create_event(start_time_str, summary, duration=1, description='D2L', location='Online'):
matches = list(datefinder.find_dates(start_time_str))
now = datetime.datetime.now()
thisYear = now.year
if len(matches):
start_time = matches[0]
end_time = start_time+datetime.timedelta(hours=1)
event = {
'summary': summary,
'location': location,
'description': description,
'start': {
'dateTime': start_time.strftime("%Y-%m-%dT%H:%M:%S"),
'timeZone': 'Canada/Newfoundland',
},
'end': {
'dateTime': end_time.strftime("%Y-%m-%dT%H:%M:%S"),
'timeZone': 'Canada/Newfoundland',
},
'reminders': {
'useDefault': False,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
},
}
return service.events().insert(calendarId='primary', body=event).execute()
create_event('april 9 10 pm', 'assessment_name')