diff options
author | Yann Leboulanger <asterix@lagaule.org> | 2013-05-15 21:04:59 +0400 |
---|---|---|
committer | Yann Leboulanger <asterix@lagaule.org> | 2013-05-15 21:04:59 +0400 |
commit | cdc892c614c7329b7fd799ed22d1b0338a485091 (patch) | |
tree | d678c1b757b9a2206302161bbb8dec2809a085ff /birthday_reminder | |
parent | 7d176c53db6e935ef78979c7b06021c62b54a9fb (diff) |
add 1 day timeout for reminders and prevent some traceback when date format is not correct
Diffstat (limited to 'birthday_reminder')
-rw-r--r-- | birthday_reminder/manifest.ini | 2 | ||||
-rw-r--r-- | birthday_reminder/plugin.py | 31 |
2 files changed, 21 insertions, 12 deletions
diff --git a/birthday_reminder/manifest.ini b/birthday_reminder/manifest.ini index c2630e7..fa523ea 100644 --- a/birthday_reminder/manifest.ini +++ b/birthday_reminder/manifest.ini @@ -1,7 +1,7 @@ [info] name: Birthday reminder short_name: birthday_reminder -version: 0.0.1 +version: 0.0.2 description: Birthday reminder plugin authors: Evgeniy Popov <evgeniypopov@gmail.com> homepage: https://bitbucket.org/axce1/bday diff --git a/birthday_reminder/plugin.py b/birthday_reminder/plugin.py index 7b20f20..6476685 100644 --- a/birthday_reminder/plugin.py +++ b/birthday_reminder/plugin.py @@ -2,6 +2,7 @@ import os import glob import datetime from xml.dom.minidom import * +import gobject from plugins import GajimPlugin from plugins.helpers import log_calls @@ -20,11 +21,9 @@ class BirthDayPlugin(GajimPlugin): configpath = configpaths.ConfigPaths() cache_path = configpath.cache_root self.vcard_path = os.path.join(cache_path, 'vcards') + os.sep + self.timeout_id = 0 - - @log_calls('BirthDayPlugin') - def activate(self): - + def check_birthdays(self): vcards = [] date_dict = {} for jid in glob.glob(self.vcard_path + '*@*'): @@ -34,24 +33,26 @@ class BirthDayPlugin(GajimPlugin): for xmldoc in vcards: try: xml = parse(xmldoc) - except: pass - else: name = xml.getElementsByTagName('BDAY') for node in name: try: data = node.childNodes[0].nodeValue date_dict[xmldoc[len(self.vcard_path):]] = data - except: pass + except: + pass today = datetime.date.today() for key, value in date_dict.iteritems(): - convert_date = datetime.datetime.strptime(value, "%Y-%m-%d") - user_bday = datetime.date( - today.year, convert_date.month, convert_date.day) + try: + convert_date = datetime.datetime.strptime(value, "%Y-%m-%d") + user_bday = datetime.date(today.year, convert_date.month, + convert_date.day) + except: + continue if user_bday < today: user_bday = user_bday.replace(year=today.year+1) @@ -72,8 +73,16 @@ class BirthDayPlugin(GajimPlugin): text = "Today BDay %s" % key if text: popup('', key, key, title=title, text=text) + return True + + @log_calls('BirthDayPlugin') + def activate(self): + self.check_birthdays() + self.timeout_id = gobject.timeout_add_seconds(24*3600, + self.check_birthdays) @log_calls('BirthDayPlugin') def deactivate(self): - pass + if self.timeout_id > 0: + gobject.source_remove(self.timeout_id) |