I am exploring python with google calendar and sheets API. Basically it should take certain events in my calendar, count how many there are, and put it in my sheets.
I got some date information like this in an array from the google calendar api quick start example so I know I can read the data, but I need to process it from per day to per week.
2017-10-23 work
2017-10-24 work
I would like to collapse them into weeks. So the above two lines should be collapsed into this line:
Oct 23- Oct 29 2 #2 instances of work.
But I am not sure how to achieve that.
datetime.date
has aisocalendar()
method that returns a tuple from wich you could get the calendar week.For example, using the data you've got in the array from the Google Calendar API:
Note that both events happen on the 43rd week of the year.
To get only the week:
From there, you could identify if an event is repeated within the same week. An extra bit of coding will be required to process all the dates, parse them into weeks, and aggregate them, but the core will be identifying the events by week, and you do that with
datetime.datetime.isocalendar()
.Hope it's useful!