From 8b3cd59cfee28b95456e9db6454a42c9c71bc827 Mon Sep 17 00:00:00 2001
From: Evgeniy Popov <evgeniypopov@gmail.com>
Date: Wed, 15 May 2013 19:17:35 +0600
Subject: [PATCH] BirthdayReminderPlugin. Initial commit

---
 birthday_reminder/__init.py__  |  1 +
 birthday_reminder/manifest.ini |  7 +++
 birthday_reminder/plugin.py    | 79 ++++++++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+)
 create mode 100644 birthday_reminder/__init.py__
 create mode 100644 birthday_reminder/manifest.ini
 create mode 100644 birthday_reminder/plugin.py

diff --git a/birthday_reminder/__init.py__ b/birthday_reminder/__init.py__
new file mode 100644
index 00000000..99840b09
--- /dev/null
+++ b/birthday_reminder/__init.py__
@@ -0,0 +1 @@
+from plugin import BirthDayPlugin
diff --git a/birthday_reminder/manifest.ini b/birthday_reminder/manifest.ini
new file mode 100644
index 00000000..40dc5510
--- /dev/null
+++ b/birthday_reminder/manifest.ini
@@ -0,0 +1,7 @@
+[info]
+name: Birthday reminder
+short_name: BDay
+version: 0.0.1
+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
new file mode 100644
index 00000000..7b20f205
--- /dev/null
+++ b/birthday_reminder/plugin.py
@@ -0,0 +1,79 @@
+import os
+import glob
+import datetime
+from xml.dom.minidom import *
+
+from plugins import GajimPlugin
+from plugins.helpers import log_calls
+from notify import popup
+
+from common import configpaths
+
+
+class BirthDayPlugin(GajimPlugin):
+
+    @log_calls('BirthDayPlugin')
+    def init(self):
+
+        self.config_dialog = None
+        self.description = ('Birthday reminder plugin')
+        configpath = configpaths.ConfigPaths()
+        cache_path = configpath.cache_root
+        self.vcard_path = os.path.join(cache_path, 'vcards') + os.sep
+
+
+    @log_calls('BirthDayPlugin')
+    def activate(self):
+
+        vcards = []
+        date_dict = {}
+        for jid in glob.glob(self.vcard_path + '*@*'):
+            if os.path.isfile(jid):
+                vcards.append(jid)
+
+        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
+
+        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)
+
+            if user_bday < today:
+                user_bday = user_bday.replace(year=today.year+1)
+
+            time_to_bday = abs(user_bday - today)
+            title = "BirthDay Reminder"
+            text = None
+
+            if time_to_bday.days > 5:
+                continue
+            if time_to_bday.days == 5:
+                text = "5 days before BDay %s" % key
+            elif time_to_bday.days == 3:
+                text = "3 days before BDay %s" % key
+            elif time_to_bday.days == 1:
+                text = "Tommorrow BDay %s" % key
+            elif time_to_bday.days == 0:
+                text = "Today BDay %s" % key
+            if text:
+                popup('', key, key, title=title, text=text)
+
+    @log_calls('BirthDayPlugin')
+    def deactivate(self):
+        pass
+
-- 
GitLab