#! /usr/bin/python # this is a script for converting birthday files into a format for use in remind # it uses the file ~/.birthdays as input, since its the default input file for birthday # output can be piped away # # author: markus.decke@phoetry.de # COPYRIGHT: GPLv2 # import re import datetime import calendar from calendar import month_abbr current = datetime.datetime.now() birthdays_file = open('.birthdays','r') #// regex matches entries in birthday file =DD/MM/YYYY birthday_filter = re.compile('[\w\s]+[=][\s]*[\d+/\d+][/\d]*') # abbreviated month names in english, starting from 0 to 12 # note : 0 will return an empty String # In the class calendar there is a month_abbr for this, # since it uses the system locale it can cause problems for remind # Only used if MONTHS and month_abbr are not equal MONTHS = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] # test if the python set locale will make output not fit for remind if list(MONTHS) == list(month_abbr): MONTHS = month_abbr # suffix for a nice sentence in remind suffix = "th" for line in birthdays_file: birthdays = birthday_filter.match(line) if birthdays: entry = birthdays.group() seperate = entry.split('=') name = seperate[0] date = seperate[1].split('/') if len(date)>0: day = date[0] if len(date)>1: month = date[1] if len(date)>2: year = date[2] else: year = "" #output #use abbrieviated month names for use in remind abbr= month_abbr[int(month)] # if year is set print the age if year: # abbr= month_abbr[int(month)] print 'REM %(day)s %(abbr)s MSG %(name)s\'s [ord(year(current())-%(year)s)] birthday' % vars() else: print 'REM %(day)s %(abbr)s MSG %(name)s\'s birthday' % vars()