From 66f53f5022afe16f34387261e607b2da42bf8f2e Mon Sep 17 00:00:00 2001 From: lovetox Date: Sun, 1 May 2022 08:48:52 +0200 Subject: [PATCH] [birthday_reminder] Remove plugin Not compatible with 1.4 anymore --- birthday_reminder/__init__.py | 1 - birthday_reminder/birthday_reminder.png | Bin 813 -> 0 bytes birthday_reminder/plugin.py | 144 ------------------------ 3 files changed, 145 deletions(-) delete mode 100644 birthday_reminder/__init__.py delete mode 100644 birthday_reminder/birthday_reminder.png delete mode 100644 birthday_reminder/plugin.py diff --git a/birthday_reminder/__init__.py b/birthday_reminder/__init__.py deleted file mode 100644 index a07a3bd..0000000 --- a/birthday_reminder/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .plugin import BirthDayPlugin diff --git a/birthday_reminder/birthday_reminder.png b/birthday_reminder/birthday_reminder.png deleted file mode 100644 index d6a8c447b1da68ccd95b94f3eb1446e80ed43c5b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 813 zcmV+|1JeA7P)QvS z<|TYkD@cMeFpQ9-%R@aBtsX+GvG6T^33Tm>tiA3hC)>MdMcuzobAZT~Ihq^=T&urzj{%JJIjP9vZr?w0|`2ls$X# zETwc2147tFTV}FKHq8%|Ud%qxMDw_ed`AozUN4nDC!E2C1j+g?6-`#?hg9|Q?fw_Q}996 rQ%m0irG&T!OE=zMkiGx^jem)62`ePWGhdQJ00000NkvXXu0mjf^JH0f diff --git a/birthday_reminder/plugin.py b/birthday_reminder/plugin.py deleted file mode 100644 index 9c10707..0000000 --- a/birthday_reminder/plugin.py +++ /dev/null @@ -1,144 +0,0 @@ -# This file is part of Birthday Reminder. -# -# Birthday Reminder is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published -# by the Free Software Foundation; version 3 only. -# -# Birthday Reminder is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Birthday Reminder. If not, see . - -import json -import datetime -import logging -from pathlib import Path - -from gi.repository import GLib - -from gajim.common import configpaths -from gajim.common import app -from gajim.common import ged -from gajim.common.events import Notification - -from gajim.plugins import GajimPlugin -from gajim.plugins.plugins_i18n import _ - - -log = logging.getLogger('gajim.p.birthday') - -TITLE = _('Birthday Reminder') -TEXT = _('Send your best wishes to %s') - - -class BirthDayPlugin(GajimPlugin): - def init(self): - self.config_dialog = None - self.description = _('Checks vCards of your contacts for upcoming ' - 'birthdays and reminds you on that day.') - self.events_handlers = { - 'vcard-received': (ged.GUI2, self._vcard_received) - } - - self._timeout_id = None - self._timeout_id_start = None - - self.showed_accounts = [] - - self._birthdays = {} - self._load_birthdays() - - def activate(self): - self._timeout_id_start = GLib.timeout_add_seconds( - 5, self._check_birthdays_at_start) - self._timeout_id = GLib.timeout_add_seconds( - 86400, self._check_birthdays) # 24h - - def deactivate(self): - if self._timeout_id is not None: - GLib.source_remove(self._timeout_id) - if self._timeout_id_start is not None: - GLib.source_remove(self._timeout_id_start) - - def _load_birthdays(self): - data_path = Path(configpaths.get('PLUGINS_DATA')) - path = data_path / 'birthday_reminder' / 'birthdays.json' - if not path.exists(): - return - with path.open('r') as file: - content = file.read() - if content: - self._birthdays = json.loads(content) - - def _store_birthdays(self): - data_path = Path(configpaths.get('PLUGINS_DATA')) - path = data_path / 'birthday_reminder' - if not path.exists(): - path.mkdir(parents=True) - - filepath = path / 'birthdays.json' - with filepath.open('w') as file: - json.dump(self._birthdays, file) - - def _vcard_received(self, event): - birthday = event.vcard_dict.get('BDAY') - if not birthday: - if event.jid in self._birthdays: - del self._birthdays[event.jid] - log.info('Received empty birthday: %s', event.jid) - else: - try: - year, month, day = birthday.split('-') - year = int(year) - month = int(month) - day = int(day) - except Exception: - log.warning('Invalid date: %s', birthday) - if event.jid in self._birthdays: - del self._birthdays[event.jid] - else: - self._birthdays[event.jid] = (year, month, day) - log.info('Received birthday: %s %s', - event.jid, (year, month, day)) - self._store_birthdays() - - def _check_birthdays_at_start(self): - self._check_birthdays() - - def _check_birthdays(self): - log.info('Check birthdays...') - today = datetime.date.today() - for jid, birthdate in self._birthdays.items(): - year, month, day = birthdate - if today.month == month and today.day == day: - account, contact = self._find_contact(jid) - if contact is None: - if jid in self._birthdays: - del self._birthdays[jid] - self._store_birthdays() - continue - else: - log.info('Issue notification for %s', jid) - name = GLib.markup_escape_text(contact.name) - app.ged.raise_event( - Notification(account=account, - jid=jid, - type='reminder', - title=TITLE, - text=TEXT % name, - icon_name='trophy-gold')) - return True - - @staticmethod - def _find_contact(jid): - accounts = app.settings.get_active_accounts() - for account in accounts: - client = app.get_client(account) - item = client.get_module('Roster').get_item(jid) - if item is not None: - contact = client.get_module('Contacts').get_contact(jid) - return account, contact - return None, None