forked from cclauss/Ten-lines-or-less
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbirthdays.py
32 lines (25 loc) · 836 Bytes
/
birthdays.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Prints a list of birthdays in your address book (in days from now).
NOTE: This script requires access to your contacts in order to work.
"""
import contacts, datetime # noqa
def days_until_next(date):
now = datetime.datetime.now()
inc = int(datetime.datetime(now.year, date.month, date.day) < now)
return (datetime.datetime(now.year + inc, date.month, date.day) - now).days
text = "\n".join(
"* {p.first_name} in {days} days".format(**x)
for x in sorted(
(
{"p": p, "days": days_until_next(p.birthday)}
for p in contacts.get_all_people()
if p.birthday
),
key=lambda x: x["days"],
)
) # noqa
print(
"Upcoming Birthdays:\n{}\n{}".format("=" * 19, text)
if text
else "You don't have any birthdays in your address book."
) # noqa