#!/usr/bin/env python # # GMinder will search through your gmail contacts and look for # stored birthdays. It will then send you an email reminder if the # date is within one week. # # released under the GPL, v2.0, yadda yadda yadda # # Alex "can't remember birthdays" Chiang # alex@chizang.net, 9/13/2005 import re import time import datetime import libgmail # global variables # warning_days is the threshold where gminder will start emailing you # notify_email is the address where the reminder will be sent (you can # obviously set it to the same address as gmail_login if you like) warning_days = 7 notify_email = "johnny@example.com" gmail_login = "yourlogin@gmail.com" gmail_passwd = "gmailpassword" # create a GmailAccount and log in ga = libgmail.GmailAccount(gmail_login, gmail_passwd) ga.login() # get a GmailcontactList gcl = ga.getContacts() # retrieve array of all GmailContacts gcontacts = gcl.getAllContacts() # girls are johnny's too. see george carlin for johnny in gcontacts: name = johnny.getName() notes = johnny.getNotes() # extract the birthday field from the notes and stick it in groups. # for the regexp "birthday: 12/30/1978" we get: # bdate.group(1) = 12/30/1978 # bdate.group(2) = 12 # bdate.group(3) = 30 # bdate.group(4) = 1978 # TODO: make this regexp a bit more flexible. currently, it requires # leading zeroes, etc. bdate = re.match("birthday: ((\d\d)/(\d\d)/(\d\d\d\d)).*?", notes) if bdate: today = datetime.date.today() bmonth = int(bdate.group(2)) bday = int(bdate.group(3)) byear = int(bdate.group(4)) # bingo is johnny's special day this year. if it is positive, # we know it's in the future. if it's negative, it's already # past, and we don't do anything bingo = datetime.date(today.year, bmonth, bday) diff = bingo - today if diff.days > 0 and diff.days < warning_days: # start creating a message with the number of days # til bingo. sdays = str(diff.days) msg = name + "'s birthday in " + sdays + " days! " # if we have a birthyear, let's figure out how old # johnny is. if byear != 0: dyears = today.year - byear msg = msg + "Turning " + str(dyears) + "." # compose and send a reminder email to address # specified above in globals subj = name + "'s birthday reminder" gcm = libgmail.GmailComposedMessage(notify_email, subj, msg) ga.sendMessage(gcm)