Archive for the 'Open Source' Category

Python – Relative datetime formatting

I wanted a function in Python to get a relative datetime string formatting. For a given datetime object, it should be compared with the current date/time and a relative date/time format should be given as output.

For example, given a date/time lets say (July 2, 2007 7:00 pm) the output should be 7:00 pm Monday, while for October 3, 1980 6:00 am, it should give just 10/03/1980. I googled a lot, but didn’t get any code to copy. So I had to write my own. If anybody needs it from now on, you can take it from here.

#!/usr/bin/env python

import datetime

def getRelativeDateTime(date, now = None): 

    if not now:	now = datetime.now()

    diff = date.date() -­ now.date()

    if diff.days == 0:#Today

        return 'at ' + date.strftime("%I:%M %p")## at 05:45 PM

    elif diff.days == ­1:#Yesterday

        return 'at ' + date.strftime("%I:%M %p") + ' Yesterday'## at 05:45 PM Yesterday

    elif diff.days == 1:#Tomorrow

        return 'at ' + date.strftime("%I:%M %p") + ' Tomorrow'## at 05:45 PM Tomorrow

    elif diff.days < ­7:#Within one week back

        return 'at ' + date.strftime("%I:%M %p %A")## at 05:45 PM Tuesday

    else:

        return 'on ' + date.strftime("%m/%d/%Y")## on 10/03/1980

Ubuntu Feisty Fawn (7.04) and OpenOffice.org

The OpenOffice.org package (2.2.0-1ubuntu3) that comes with Ubuntu Feisty Fawn distribution has some issues especially on the document conversion front. I did not face any problem on my dektop edition installed directly from the feisty fawn dvd. But on the server edition the conversion was taking almost 20x more time. On googling it seemed to be a problem with the java compilation on the OpenOffice package from Ubuntu.

The best and easiest remedy is to uninstall your current OpenOffice.org packages completely and install the latest OpenOffice 2.2.1 from directly from www.openoffice.org. Installation is a bit tricky so I suggest you take a look at this article where the installation is described step by step.

You might have to install msttcorefonts package if you start facing issues with windows fonts once you install OpenOfiice 2.2.1.

OpenOffice as a Document Converter

Though not well known for it, OpenOffice.org can be extended as a doument conversion engine capable of conversion between almost all kind of office documents. OpenOffice.org directly doesn’t support a command-line option, but allows it to be run as a service. An open source tool JodConverter (earlier called JooConverter) provides a wrapper for the OpenOffice.org service and exposes web and command-line interaces to simply convert between the compatible office formats.

Read Full Article by Dmitry Popov at Linux.com