diff --git a/birthdays-cal.py b/birthdays-cal.py index f7deb65..33304d2 100644 --- a/birthdays-cal.py +++ b/birthdays-cal.py @@ -1,16 +1,22 @@ # -*- coding: utf-8 -*- -import sys -import yaml import datetime import hashlib +import sys +from bisect import bisect +import yaml from icalendar import Calendar, Event one_day = datetime.date(1, 1, 2) - datetime.date(1, 1, 1) event_config = {'description': '', 'categories': '', 'language': ''} +zsigns = [(1, 20, '♑'), (2, 18, '♒'), (3, 20, '♓'), (4, 20, '♈'), + (5, 21, '♉'), (6, 21, '♊'), (7, 22, '♋'), (8, 23, '♌'), + (9, 23, '♍'), (10, 23, '♎'), (11, 22, '♏'), (12, 22, '♐'), + (12, 31, '♑')] + def load_config(): result = dict() @@ -52,6 +58,11 @@ def age(person, year): return abs(year - person['birthday'].year) +def zodiac_sign(person): + birthday = person['birthday'] + return zsigns[bisect(zsigns, (birthday.month, birthday.day))][2] + + def make_event(person, year): event_date = person['birthday'].replace(year=year) description = event_config['description'] @@ -59,7 +70,7 @@ def make_event(person, year): lang_params = {'language': event_config['language']} if 'birthday_no_year' not in person: - description += ', %d' % age(person, year) + description += ', %d %s' % (age(person, year), zodiac_sign(person)) event = Event() event.add('uid', sha1(person['name'] + ' birthday ' + str(year)))