User Tools

Site Tools


Website Twitter to Calendar Integration Script (CCHS-Twitcal)

Note: This page documents the old setup. The current setup is similar, but is written in perl, calls the twitter API directly, and fetches events out of the website calendar database. Due to changes in the calendar software used on the website, this solution will need to be re-engineered once new website calendar software is selected (changes in free options have removed iCal feed support from the free version of the website calendar software).

CCHS-Twitcal is the twitter to google calendar integration setup that as developed to tweet event reminders for CCHS.


The CCHS-Twitcal shell script posts an event to the @HackMelbourne twitter feed prior to an event. The tweet contains an appropriate header, the date/time of the event, the title of the event from the calendar, and an appropriate footer. The script is run out of cron regularly so that any updates or changes get tweeted without manual intervention.


CCHS-Twitcal follows the following steps:

  1. Checks the calendar and sees if an event is within the check interval. The check interval is defined in minutes.
  2. If an event is found, it grabs the current agenda for the calendar.
    • The agenda contains the date, which we want in the tweet, whereas reminders do not. This is the only reason we do this.
  3. We then extract only the top item in the agenda (as it's the next event, which is what we want to tweet about).
  4. Event is then 'massaged' by adding a header, a footer, and then removing all excess spaces.
  5. The “tweet” is then checked against the previous tweet, to avoid tweeting the same thing more than once.
  6. If they're different, we tweet it.
  7. Only once the tweet is successfully sent, do we write the new tweet to disk as the previous tweet, ready for the next run.

This basic process is followed twice. Once to check for events coming up soon (ie: event is about to start), and once to check for events in the futher future.


CCHS-Twitcal requires the following:

  • A Google calendar to read.
  • A Google account to access said calendar.
  • A twitter account to post to.
    • Written in python, packages exist for Ubuntu but best to use the Pkg Installer for Python (pip) to install.
    • gcalcli needs to be authorised to access the calendar (as per gcalcli docs) in advance.
    • Written in perl.
    • ttytter needs to be authorised to access the twitter account (as per ttytter docs) in advance.


Cancelling/changing events

If an event has gone out to twitter, and you want to cancel it, I recommend doing the following:

  1. Change the title of the event and append “ - CANCELLED”.
  2. Wait for the event to be automatically tweeted with the new title, or manually run to force it to tweet in advance of the normal tweet schedule.
  3. If preferred, delete the event from Google calendar, but only AFTER the tweet has gone out.

If an event has gone out to twitter, and you want to change it, I recommend doing the following:

  1. If it's simply a small change to the start time which still falls in the check interval, simply change the event details, and it will be tweeted with correct details when next run.
  2. If the event is being changed and will not fall in the check interval, then appending something to the event title to indicate this before changing the event details to the new time will result in a tweet with this information.
    • eg: The 3D printer night is moved from Monday the 6th of October to Thursday the 9th of October. Change the title to “CCHS 3D printer meeting moved to Oct Thu 9th”.
  3. Wait for the event to be automatically tweeted with the new title, or manually run to force it to tweet in advance of the normal tweet schedule.
  4. Move the event to the new date/time, and change the title.

Note: Of course, you could just tweet changes manually in either case. However, if you don't have direct access to the twitter account and the script is scheduled to run regularly (eg: every 30-60 mins), the above should work, as long as you have access to the Google calendar to change it.

The Script

The script is fairly parametrised, so that everything is pretty much variables at the top. This should allow someone to modify/reuse the script for a different group/calendar/etc easily. It's also very well documented. I've removed the old version of the script from this page as it has changed quite a bit from the version previously posted. If you update the script, please make sure to keep the documentation within the script up to date (including incrementing the version number).


gcalcli cannot read a calendar anonymously, which means you MUST have a google account to access the calendar. This IMO is sub-optimal, but I haven't found any other tool that could be used to access the calendar from a script easily. Also, gcalcli ties us to Google calendar, instead of something like using ical, which would allow usage of other calendar systems (eg: Event calendars implemented in Wordpress).


As we only tweet the nearest event(s), this means that if there are two events that follow one another, only once the first event starts will the new event be available for tweeting. This is by design, so that we don't confuse, but if you have a lot of events, it may be worth reconsidering how best to communicate these events to your twitter followers.

doc/cchs_twitcal.txt · Last modified: 2016/08/25 18:50 by cefiar