Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Tutorials & Tips
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Tutorials & Tips
The place to find Ubuntu related Tips & Tricks.

 
Thread Tools Display Modes
Old June 22nd, 2008   #1
kaivalagi
Chocolate Ubuntu Mocha Blend
 
kaivalagi's Avatar
 
Join Date: Feb 2008
Location: 52°38'41.6"N/1°19'43.6"E
Beans: 1,916
Conky Google Calendar Python Script

ArchLinux : Package support is present in the AUR. All my packages can be seen here: http://aur.archlinux.org/packages.php?SeB=m&K=kaivalagi

IMPORTANT NEWS

All the script packages have now been copied into the Conky Hardcore PPA. Any package updates will be provided by the team through this new ppa.

The ppa can be found here: https://launchpad.net/~conkyhardcore/+archive/ppa

To use this ppa first delete the old ppa files using this:
Code:
sudo rm /etc/apt/sources.list.d/m-buck*
Then follow the modified first post instructions for the scripts
__________________________________________________ __________________________________________________ ______________________________


Intro

Following on from my conkyForecast script, I've created another which may be useful to you conky users out there. conkyForecast.py can be found here -> http://ubuntuforums.org/showthread.php?p=5452132

I have put together this python script to output Google Calendar events from a users default calendar, for use in Conky. I know there are already other means to do this using the command line, however I wanted something I could modify a little more, and will no doubt do so as and when I or you come up with new ideas.

Some key features
  • Utilises the Google Calendar API.
  • Supports the use of a template to define the layout of each event output
  • Supports regional datetime formats, by way of system locales
  • Optional event limit so you can reduce the total output in Conky if you have lot's of events, events should be returned earliest first (needs testing)

There is a README with the install and attached here, I suggest you give it atleast a quick once over!

Hope some of you find it useful

Any suggestions, please speak up!

Basic Install

Method 1: Using apt

1) Create the necessary list file for access to the repository by running one of these.

Karmic Koala:
Code:
sudo wget -q http://www.kaivalagi.com/ubuntu/ppa/conkyhardcore-karmic.list -O /etc/apt/sources.list.d/conkyhardcore-karmic.list
Jaunty Jackalope:
Code:
sudo wget -q http://www.kaivalagi.com/ubuntu/ppa/conkyhardcore-jaunty.list -O /etc/apt/sources.list.d/conkyhardcore-jaunty.list
Intrepid Ibex:
Code:
sudo wget -q http://www.kaivalagi.com/ubuntu/ppa/conkyhardcore-intrepid.list -O /etc/apt/sources.list.d/conkyhardcore-intrepid.list
Hardy Heron:
Code:
sudo wget -q http://www.kaivalagi.com/ubuntu/ppa/conkyhardcore-hardy.list -O /etc/apt/sources.list.d/conkyhardcore-hardy.list
2) Add the repository public key to your apt setup by running this:

Code:
wget -q http://www.kaivalagi.com/ubuntu/ppa/conkyhardcore-key.gpg -O- | sudo apt-key add -
3) Now that is done simply run the following to install

Code:
sudo apt-get update && sudo apt-get install conkygooglecalendar
Method 2: Using deb file

Download and run the attached .deb file

Warning, this will not ensure you are kept up-to-date. Only method 1 will do that ;)

Method 3: Using tar.gz file

Extract all the contents of the attached tar.gz file to an appropriate folder, and edit the conkyEmail script to point to the correct location where conkyEmail.py is.

Unless you are using a non-Debian based OS I don't suggest this. Users of Debian/Ubuntu flavour OS's should ideally use method 1.

Again will will not receive updates using this method. ONLY method 1 can do this for you ;) ;)

All further details on setup are orientated around the deb package based install, so may differ from what you choose your setup to be, if done using the tarball.


Usage Help

You can get the current help options at any time by running (change the path as necessary):

Code:
python ~/.scripts/conkyGoogleCalendar.py -h
or

Code:
python ~/.scripts/conkyGoogleCalendar.py --help
The usage is as follows:

Code:
Usage: conkyGoogleCalendar [options]
Options:
  -h, --help            show this help message and exit
  -u USERNAME, --username=USERNAME
                        Username for login into Google Calendar, this will
                        normally be your gmail account
  -p PASSWORD, --password=PASSWORD
                        Password for login
  -r TEXT, --requestCalendarNames=TEXT
                        Define a list of calendars to request event data for,
                        calendar names should be separated by semi-colons ";".
                        For example --requestCalendarNames="cal1;cal2;other
                        cal" If not set all calendar data will be returned.
  -d NUMBER, --daysahead=NUMBER
                        [default: 7] Define the number of days ahead you wish
                        to retrieve calendar entries for, starting from today.
  -s DATE, --startdate=DATE
                        Define the start date to retrieve calendar events. In
                        the form '2007-12-01'
  -e DATE, --enddate=DATE
                        Define the end date to retrieve calendar events, must
                        be supplied if --startdate supplied. In the form
                        '2007-12-01'
  -a, --allevents       Retrieve all calendar events
  -w TEXT, --wordsearch=TEXT
                        Define the text to search calendar entries with.
  -l NUMBER, --limit=NUMBER
                        [default: 0] Define the maximum number of calendar
                        events to display, zero means no limit.
  -t FILE, --template=FILE
                        Template file determining the format for each event.
                        Use the following placeholders: [title], [starttime],
                        [endtime], [location], [description], [who]. Ensure
                        only one placeholder per line, as the whole line is
                        removed if no data for that placeholder exists.
  -f "DATEFORMAT", --dateformat="DATEFORMAT"
                        If used this overrides the default date formatting.
                        The values to use are standard formatting strings e.g.
                        Weekday=%a, Day=%d, Month=%m, Year=%y. For an output
                        like "Thu 15/10/2008" you would require
                        --dateformat="%a %d/%m/%y", to have no date you would
                        require --dateformat=""
  -F "TIMEFORMAT", --timeformat="TIMEFORMAT"
                        If used this overrides the default time formatting.
                        The values to use are standard formatting strings e.g.
                        Hours (12hr)=%l, Hours (24hr)=%H, Minutes=%M,
                        Seconds=%S, AM/PM=%P. For an output like "05:22 PM"
                        you would require --timeformat="%l:%M %P",
                        --timeformat="" is not supported, default locale
                        settings are used
  -i NUMBER, --indent=NUMBER
                        [default: 0] Define the number of spaces to indent the
                        output (excludes template based output)
  -m NUMBER, --maxwidth=NUMBER
                        [default: 40] Define the number of characters to
                        output per line
  -n, --nowho           Hides who is attending the events (excludes template
                        based output)
  -c NUMBER, --connectiontimeout=NUMBER
                        [default: 10] Define the number of seconds before a
                        connection timeout can occur.
  -v, --verbose         Request verbose output, no a good idea when running
                        through conky!
  -V, --version         Displays the version of the script.
  --errorlogfile=FILE   If a filepath is set, the script appends errors to the
                        filepath.
  --infologfile=FILE    If a filepath is set, the script appends info to the
                        filepath.

The important thing to note now is that the script is called using this in Conky:

Code:
{execi 1800 conkyGoogleCalendar ...options...}
Rather than something like this as before:

Code:
{execi 1800 python /path/to/file/conkyGoogleCalendar.py ...options...}

Notes On Script Config Values

The conkyGoogleCalendar.py script has one config value worthy of a mention. As descriptions can be long there is a limit to the amount output to conky, this is set by the following, which can be increased/reduced if so desired.

Code:
MAX_WIDTH = 47
Feel free to search and change the value if you need to.

Gotchas

Truncated Output
Conky has a default limitation of 128 bytes for any text output from a variable (such as execi). If you are creating large templates with more characters than the default buffer size can handle, the output will get truncated. If this happens you can override the default behaviour by setting as new buffer size at the top of your conkyrc file, as follows:
Code:
text_buffer_size 512
Captcha Issue
The Google calendar function can stop working for with a "GoogleCalendarEngine Initialisation:Unexpected error:Captcha Required" error message. This is something Google enforces and to overcome it simple authenticate yourself here: https://www.google.com/accounts/UnlockCaptcha

Locale and unicode support
If you receive something similar to this error "ERROR: writeOutput:Unexpected error:'ascii' codec can't decode byte 0xc3 in position 14: ordinal not in range(128)" it is because the script can't handle your locale settings for output.
To overcome this add the following above TEXT in your conkyrc:
Code:
override_utf8_locale yes

Development History

Development history going forwards can be seen here https://code.launchpad.net/~m-buck/+...googlecalendar

All packages available from me can be found here: https://launchpad.net/~conkyhardcore/+archive/ppa

I have also created a new website, for now it is relatively sparse, but it does details my conky scripts to a certain degree. You can find it here: http://www.kaivalagi.com
Attached Images
File Type: jpg conkyGoogleCalendar.jpg (43.5 KB, 1893 views)
Attached Files
File Type: txt README.txt (6.7 KB, 156 views)
File Type: deb conkygooglecalendar_2.06_all.deb (17.2 KB, 64 views)
File Type: gz conkygooglecalendar-2.06.tar.gz (25.4 KB, 121 views)
__________________

Last edited by kaivalagi; 4 Weeks Ago at 06:09 AM.. Reason: Updated, see dev history
kaivalagi is offline   Reply With Quote
Old June 22nd, 2008   #2
HippyRandall
Gee! These Aren't Roasted!
 
HippyRandall's Avatar
 
Join Date: Feb 2008
Location: N of Bruce W of Kaivalagi
Beans: 181
Ubuntu 9.10 Karmic Koala
Send a message via ICQ to HippyRandall Send a message via MSN to HippyRandall Send a message via Yahoo to HippyRandall Send a message via Skype™ to HippyRandall
Re: Conky Google Calendar Python Script

more conky stuff to play with!!

soon my whole desktop is going to be full of conky output
keep up the good work kaivalagi

Hippy
__________________
hippyrandall.com | Stargate Wars | HP Laptop
This is the first age that's paid much attention to the future, which is alittle ironic since we may not have one. -- Arthur Clarke
HippyRandall is offline   Reply With Quote
Old June 22nd, 2008   #3
Bruce M.
Chocolate Ubuntu Mocha Blend
 
Bruce M.'s Avatar
 
Join Date: Sep 2007
Location: 34°35'S - 58°21'W
My beans are hidden!
Re: Conky Google Calendar Python Script

Oh oh ... I don't use Google Calendar but may have to start.
Gotta go check it out now.

Good stuff kaivalagi, if this is half as good as your weather script it'll be very popular among the Google Calendar users.

Have a good day.
Bruce

EDIT: I'm a user now.

Last edited by Bruce M.; October 20th, 2008 at 10:05 PM..
Bruce M. is offline   Reply With Quote
Old June 22nd, 2008   #4
pmaconi
A Carafe of Ubuntu
 
Join Date: Oct 2007
Beans: 134
Re: Conky Google Calendar Python Script

Sounds cool. Could you post a screenshot?
pmaconi is offline   Reply With Quote
Old June 22nd, 2008   #5
kaivalagi
Chocolate Ubuntu Mocha Blend
 
kaivalagi's Avatar
 
Join Date: Feb 2008
Location: 52°38'41.6"N/1°19'43.6"E
Beans: 1,916
Re: Conky Google Calendar Python Script

Quote:
Originally Posted by pmaconi View Post
Sounds cool. Could you post a screenshot?
Screenshot added to the first post...

Edit: Noticed the first problem, events were not listed in date order...the google api must provide the events in the order they were created...Added a compare function to data class and sorted lists, earliest starttime first. Updated the first post
__________________

Last edited by kaivalagi; June 22nd, 2008 at 05:16 PM.. Reason: Updated script to fix event display order
kaivalagi is offline   Reply With Quote
Old June 23rd, 2008   #6
kaivalagi
Chocolate Ubuntu Mocha Blend
 
kaivalagi's Avatar
 
Join Date: Feb 2008
Location: 52°38'41.6"N/1°19'43.6"E
Beans: 1,916
Re: Conky Google Calendar Python Script

UPDATE

Just a couple of things done.

I have made sure that when using the --daysahead option to retrieve upcoming events, that no events are added that are from before the current datetime. Previously events from earlier the same day where also being output, this really isn't necessary as they're in the past.

I have also added an --indent option which when used will indent by how ever many spaces are specified. This doesn't work with the template option as spaces can be applied there instead.
  • 23/06/2008 Modified to only display current events (--daysahead option) that start after now
  • 23/06/2008 Added --indent option to add spaces to the front of each line that is output (excludes template output)

Cheers
__________________
kaivalagi is offline   Reply With Quote
Old June 23rd, 2008   #7
HippyRandall
Gee! These Aren't Roasted!
 
HippyRandall's Avatar
 
Join Date: Feb 2008
Location: N of Bruce W of Kaivalagi
Beans: 181
Ubuntu 9.10 Karmic Koala
Send a message via ICQ to HippyRandall Send a message via MSN to HippyRandall Send a message via Yahoo to HippyRandall Send a message via Skype™ to HippyRandall
Re: Conky Google Calendar Python Script

now I am going to have to start getting organized and actually putting stuff on my gcalendar...boll ox (forums edit out the correct spelling)


Hippy
__________________
hippyrandall.com | Stargate Wars | HP Laptop
This is the first age that's paid much attention to the future, which is alittle ironic since we may not have one. -- Arthur Clarke
HippyRandall is offline   Reply With Quote
Old June 24th, 2008   #8
kaivalagi
Chocolate Ubuntu Mocha Blend
 
kaivalagi's Avatar
 
Join Date: Feb 2008
Location: 52°38'41.6"N/1°19'43.6"E
Beans: 1,916
Re: Conky Google Calendar Python Script

Guess what.....UPDATE

Done quite a bit more tonight, we now have details on who is attending the events by way of email addresses. This can also be turned off using a new --nowho option. I have also fixed up the template functionality to remove unwanted whitespace only lines from the output, for situations where not all the data is available for an event.

Also done a general tidy up of the code, and put in some tweaks to make event listings generally more sensible, including having re-occuring events treated like multiple single events.

What went onto the dev history:
  • 24/06/2008 Added who is attending (email addresses) to the output of each event, added a <who> parameter for the template, and added a --nowho option to hide the data (excludes template output)
  • 24/06/2008 Fixed up template output using regex, to remove unnecessary blank lines where no data exists

Cheers,
Mark
__________________
kaivalagi is offline   Reply With Quote
Old June 24th, 2008   #9
HippyRandall
Gee! These Aren't Roasted!
 
HippyRandall's Avatar
 
Join Date: Feb 2008
Location: N of Bruce W of Kaivalagi
Beans: 181
Ubuntu 9.10 Karmic Koala
Send a message via ICQ to HippyRandall Send a message via MSN to HippyRandall Send a message via Yahoo to HippyRandall Send a message via Skype™ to HippyRandall
Re: Conky Google Calendar Python Script

You've been busy! Nice additions. I am in the process of adding events to my calendar to test some of this stuff out.
Keep coming with the new ideas!

Hippy
__________________
hippyrandall.com | Stargate Wars | HP Laptop
This is the first age that's paid much attention to the future, which is alittle ironic since we may not have one. -- Arthur Clarke
HippyRandall is offline   Reply With Quote
Old June 30th, 2008   #10
PurposeOfReason
100% Pure Ubuntu
 
PurposeOfReason's Avatar
 
Join Date: May 2007
Location: Washington
Beans: 914
Send a message via AIM to PurposeOfReason
Re: Conky Google Calendar Python Script

Quite nice. Do you think it will be possible to align things left and right?
PurposeOfReason is offline   Reply With Quote

Bookmarks

Tags
calendar, conky, gdata, google, python

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:28 AM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. bilberry