Notice: This code and the corresponding google API have changed several times since this was first published. It is currently not stable, so do not rely on this being reliable or even working. I will try and remedy the stability of it, but currently this is low on my list of priorities.
Google calendar makes sweet love to your alarm clock
(Inspired from Raspberry Pi as a Google Calender Alarm Clock)
This year, my kids started riding the school bus, which is super convenient and means I don't have to spend extra time getting them to school. That is, if they make the bus. Sometimes they lose track of time, and I wanted a pretty reliable way of reminding them when it's time to go outside to wait for the big yellow limousine to escort them to school.
Since I am lazy, I decided to have this automated, which uses (ideally) a Raspberry Pi and Google Calendar to check for events that start with 'say' or have corresponding mp3 titles.
For example:
- An event titled
say Don't forget to brush your teeth
will announce the phrase 'Don't forget to brush your teeth'. - An event with the title
Get on the bus
fires an appropriately annoying song snippet from the mp3s folder by The Doodlebops calledget_on_the_bus.mp3
.
It's dynamic in the sense that it will try and play any mp3 with the event title, and falls back to a default mp3 (my default.mp3 is an old school Nokia ringtone-- of course, you can make yours anything you wish).
Pre-requisite: mpg123
-
If you're on Linux, you can install
mpg123
via apt-get:sudo apt-get install mpg123
-
If you're on OS X, you can install
mpg123
via Homebrew:brew install mpg123
-
Or you can download the source and run:
./configure make make install
Pre-requisite for Linux text to speech: espeak
sudo apt-get install espeak
-
Install the requirements:
pip install -r requirements.txt
-
Create a new project on the Google Developers Console
-
Enable the Calendars API
-
Create the file
config.py
-
Create new Client ID for web application and download the JSON as
client_secrets.json
and setCLIENT_SECRET_FILE = 'client_secrets.json'
inconfig.py
-
Create a new key for browser application and set the
API KEY
value asAPI_KEY = xxx
inconfig.py
-
Create a new Google calendar and set the ID as
CALENDAR_ID = xxx
inconfig.py
(Click drop-down arrow by calendar name; choose 'Calendar Settings'; find ID by 'Calendar Address' section) -
Add
FREQUENCY_CHECK
(in seconds) andMP3_FOLDER
location inconfig.py
. -
Run the program:
python alarm.py
All new events will try to play the name of the event as an mp3 file in the mp3s
folder with spaces converted to underscores, i.e.:
Get on the bus
== mp3s/get_on_the_bus.mp3
If the event has no corresponding mp3 file, default.mp3
will play. To have the sound play repeatedly until the event's time expires, enter repeat
as the event's description.
Example config.py
file:
API_KEY = '123456789qwertyuiop987654321asdfghjkl54321'
CALENDAR_ID = '[email protected]'
CLIENT_SECRET_FILE = 'client_secrets.json'
FREQUENCY_CHECK = 5 # in seconds
MP3_FOLDER = 'mp3s'