This page looks best with JavaScript enabled

Integration of Google Calendar events with Awesome

 ·  🎃 kr0m

The work will be divided into two parts:

  • Bash script to obtain and parse events
  • LUA widget that reads the file generated by the bash script

First, we will install the tool that will download the events from our Google Calendar:

cd /usr/src/
git clone https://github.com/insanum/gcalcli.git
cd gcalcli
python setup.py install
emerge dev-python/pip
pip install vobject parsedatetime
emerge dev-python/google-api-python-client

Now we create the script that will parse the output of the previous tool and generate the file with the correct syntax to be read by the LUA widget:

vi ~/.scripts/cal.sh

#! /bin/bash
NOW=$(date '+%Y-%m-%d %H:%m')
NOWEPOCH=$(date +%s)
#echo -e "NOW: $NOW"
#echo -e "NOWEPOCH: $NOWEPOCH"
# 30days --> 2592000
ENDEPOCH=$((ENDEPOCH=NOWEPOCH+2592000))
#echo -e "ENDEPOCH: $ENDEPOCH"
END=$(date -d @$ENDEPOCH '+%Y-%m-%d %H:%m')
#echo -e "END: $END"

> /tmp/tareas

IFSORI=$IFS
IFS=$'
'
for LINE in $(/usr/bin/gcalcli --tsv --calendar CALENDARIO1 --calendar CALENDARIO2 --calendar CALENDARION agenda "'$NOW'" "'$END'")
do
    YEAR=$(echo $LINE|awk -F "-" '{print$1}')
    #echo -e "-- YEAR: $YEAR"
    MONTH=$(echo $LINE|awk -F "-" '{print$2}')
    #echo -e "-- MONTH: $MONTH"
    DAY=$(echo $LINE|awk -F "-" '{print$3}'|awk -F " " '{print$1}')
    #echo -e "-- DAY: $DAY"
    case $MONTH in
        01) MONTHLETTERS=Jan ;;
        02) MONTHLETTERS=Feb ;;
        03) MONTHLETTERS=Mar ;;
        04) MONTHLETTERS=Apr ;;
        05) MONTHLETTERS=May ;;
        06) MONTHLETTERS=Jun ;;
        07) MONTHLETTERS=Jul ;;
        08) MONTHLETTERS=Aug ;;
        09) MONTHLETTERS=Sep ;;
        10) MONTHLETTERS=Oct ;;
        11) MONTHLETTERS=Nov ;;
        12) MONTHLETTERS=Dec ;;
    esac
    #echo -e "-- MONTHLETTERS: $MONTHLETTERS"
    TXT=$(echo $LINE|cut -f5-)
    #echo -e "-- TXT: $TXT"
    echo -e "** $TXT" >> /tmp/tareas
    echo -e "SCHEDULED: <$YEAR-$MONTH-$DAY $MONTHLETTERS>" >> /tmp/tareas
done
IFS=$IFSORI
chmod 700 ~/.scripts/cal.sh

We perform the first execution so that it asks us for the credentials of the Gmail account, from this moment gcalcli will store these credentials:

/usr/bin/gcalcli –tsv –calendar CALENDAR1 –calendar CALENDAR2 –calendar CALENDAR agenda “’$NOW’” “’$END'”

NOTE: It may try to open the web to give access to the account with a browser without javascript, if this is the case before executing the script we will indicate the browser to use:

export BROWSER=“firefox”

We put the script in the cron to run every 5 minutes:

crontab -e

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

*/5 * * * * /home/XXXX/.scripts/cal.sh >/dev/null 2>&1

We download the widget:

NOTE: The widget on my website has been modified so that the week starts on Monday, the previous script imposes the restriction that calendar events cannot have spaces, it can be replaced by _ for example, for more information about the widget ,

We integrate the widget into the clock:

vi rc.lua

-- Create a textclock widget
mytextclock = awful.widget.textclock({ align = "right" })
local orglendar = require('orglendar')
orglendar.files = { "/tmp/tareas" }
orglendar.register(mytextclock)

With this, we have everything set up. Now, when the mouse hovers over the clock, a calendar and a list of events will be displayed. The result is as follows:

If you liked the article, you can treat me to a RedBull here