InkypHAT - show Google Calendar appointments

Dear forum-members,

I just bought a RPi ZeroW and an InkypHAT and was planning to show some information on it.
The weather should be no problem, the date should also be no problem but…
The one thing that I’m not sure how to show are the calendar appointments for a Google Calendar account. If those are multiple appointments I’d like to show them in a scrolling textbox. How can I achieve this?
Many thanks for your help!

Kind regards,
Yerroon

I looked briefly into this and determined the easiest short-term way would be to export the ical file and use that. It could, in theory, be done with the Google calendar API but it’s not exactly user-friendly if you’re not used to dealing with APIs and authentication: https://developers.google.com/google-apps/calendar/quickstart/python

I decided to go onto the download ICS file route. But I’m stuck at making a script that shows all appointments for a day with their starting hour…
I think the problem lies in the fact that there are events that are ‘whole day’ events and events that have a start time and an end time.
I get the error “can’t compare datetime.datetime to datetime.date” And I’m guessing that has something to do with the fact that sometimes the DTSTART of an event is sometimes a date and sometimes a datetime type…

Can someone help me?

Is there nobody that can help me?

It’s just that “datetime.datetime” and “datetime.date” are, for better or worse, fundamentally different types.

>>> datetime.date.today()
datetime.date(2017, 9, 14)
>>> datetime.datetime.now()
datetime.datetime(2017, 9, 14, 14, 9, 22, 813828)

Since one includes information about the time, they cannot be meaningfully compared with normal operators:

>>> x = datetime.date.today()
>>> y = datetime.datetime.now()
>>> x == y
False
>>> x > y
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't compare datetime.datetime to datetime.date

You have to be specific about what you want to compare:

>>> (x.day, x.month, x.year) == (y.day, y.month, y.year)
True

Or, more simply, just ask datetime for its date component:

>>> x = datetime.date.today()
>>> y = datetime.datetime.now()
>>> x == y
False
>>> x == y.date()
True

Thank you very much for your post, very clear. Now I’m hitting the next problem: when I create a repeating event, I cannot test if the start or end date match the current day. Is there a way around this?

Ooh, how is a repeating event stored in the ics file? I don’t think I tried one of those.

It is something like:

start_date: x
end_date: y
repeats_every: wednesday
at: 5pm

Edit, ooh it looks something like this in the ics code:

DTSTART: 20160104T130000Z
DTEND: 20160104T140000Z
RRULE: FREQ=WEEKLY; UNTIL=20170101T000000Z

So I guess how you check depends rather heavily on what the “FREQ” is set to. If it’s daily then you just need to verify that it’s between the start/end dates and the start/end times separately.

Weekly could be trickier- what if it’s a two day event? :D

Oh bugger me with a fishfork, this whole project is getting a bit over my head I’m afraid…
Still, I get the distinct feeling that I’m reinventing the wheel here: surely somebody must have tackled this problem a long time ago?

Or should I go back to the Google API route?

Yeah I certainly wasn’t overly impressed by the iCalendar library, it opens export files but that’s about it.

I wanted to put together a Google Calendar API example, but it seemed complex too and a lot for a basic API user to get started with.

I got it running, lots of blood sweat and tears but very rewarding in the end.

Now I’m dealing with the following issue: I cannot get my script to run in the crontab.

0 7 * * * python /home/pi/Pimoroni/inkyphat/examples/dashboard_kids.py &>> /home/pi/log_dashboard.txt

Not working…
Start of the script: #!/usr/bin/python
The log_dashboard.txt is also empty

I see Python running in ‘top’, then it quits and the results are nothing…

Any help?

Does the script rely on any files also in that folder?

To run stuff in crontab I usually write a startup bash script, named something like “start.sh” with:

#!/bin/bash
cd /home/pi/Pimoroni/inkyphat/examples
python dashboard_kids.py >> log_dashboard.txt

Then run in crontab with bash /home/pi/Pimorni/inkyphat/examples/start.sh

It’s all fine now! Some details to iron out though, but very pleased with the result! And, it gets used every day! :-D

1 Like

Hi Phil

This has been the best solution for running the inkyphat scripts via crontab.

Thank you very much.

Regards

Cathy

1 Like