-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathholidays.py
29 lines (25 loc) · 1.12 KB
/
holidays.py
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
import datetime
import pandas as pd
import google_api
def getHolidays():
service = google_api.get_service('calendar', 'v3')
now = (pd.to_datetime(datetime.datetime.utcnow()) +
datetime.timedelta(days=2, hours=5, minutes=30))
later = (now + datetime.timedelta(days=6, hours=5, minutes=30))
# print (now.date().isoformat(), later.date().isoformat())
now = now.isoformat() + 'Z'
later = later.isoformat() + 'Z'
# print('Getting the upcoming 10 events')
events_result = service.events().list(calendarId=calendarId, timeMin=now,timeMax=later,
singleEvents=True,orderBy='startTime').execute()
events = events_result.get('items', [])
holidays = [5,6]
if not events:
print('No upcoming events found.')
for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
# print(start, event['summary'], pd.to_datetime(start).dayofweek)
if (pd.to_datetime(start).dayofweek not in holidays):
holidays.append(pd.to_datetime(start).dayofweek)
return sorted(holidays)