def handle_checkbd(bot, ievent): """ bd-check .. check birthdays for current month """ global db if not db: ievent.reply("plugin isnt initialised yet") ; return (nowday, nowmonth) = getdaymonth(time.time()) mstr = "" result = [] bds = db.execute(""" SELECT * FROM birthday """) if not bds: ievent.reply('no birthdays this month') ; return for i in bds: btime = strtotime(i[1]) if btime == None: continue (day, month) = getdaymonth(btime) if month == nowmonth: result.append((int(day), i[0], i[1])) if day == nowday and month == nowmonth: ievent.reply("it's %s's birthday today!" % i[0]) result.sort(lambda x, y: cmp(x[0], y[0])) for i in result: mstr += "%s: %s " % (i[1], i[2]) if mstr: mstr = "birthdays this month = " + mstr ; ievent.reply(mstr) else: ievent.reply('no birthdays this month')
def handle_checkbd2(bot, ievent): """ bd-check <nr> .. show birthdays in month (by number) """ global db if not db: ievent.reply("plugin isnt initialised yet") ; return try: monthnr = int(ievent.args[0]) if monthnr < 1 or monthnr > 12: ievent.reply("number must be between 1 and 12") ; return except (IndexError, ValueError): ievent.missing('<monthnr>') ; return mstr = "" result = [] bds = db.execute(""" SELECT * FROM birthday """) if not bds: ievent.reply('no birthdays known') ; return for i in bds: btime = strtotime(i[1]) if btime == None: continue (day, month) = getdaymonth(btime) if month == bdmonths[monthnr]: result.append((int(day), i[0], i[1])) result.sort(lambda x, y: cmp(x[0], y[0])) for i in result: mstr += "%s: %s " % (i[1], i[2]) if mstr: mstr = "birthdays in %s = " % bdmonths[monthnr] + mstr ; ievent.reply(mstr) else: ievent.reply('no birthdays found for %s' % bdmonths[monthnr])