-
Notifications
You must be signed in to change notification settings - Fork 0
/
birthday.py
56 lines (50 loc) · 1.78 KB
/
birthday.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from datetime import datetime
def get_birthdays_per_week(users):
current_datetime = datetime.now().date()
monday = f"Monday:"
count_monday = 0
tuesday = f"Tuesday:"
count_tuesday = 0
wednesday = f"Wednesday:"
count_wednesday = 0
thursday = f"Thursday:"
count_thursday = 0
friday = f"Friday:"
count_friday = 0
for ch in users:
for name, date in ch.items():
new_datetime = date.replace(year=current_datetime.year).date()
difference = new_datetime - current_datetime
if 0 < difference.days <= 7:
if new_datetime.weekday() in [0, 5, 6]:
monday += f" {name},"
count_monday += 1
elif new_datetime.weekday() == 1:
tuesday += f" {name},"
count_tuesday += 1
elif new_datetime.weekday() == 2:
wednesday += f" {name},"
count_wednesday += 1
elif new_datetime.weekday() == 3:
thursday += f" {name},"
count_thursday += 1
elif new_datetime.weekday() == 4:
friday += f" {name},"
count_friday += 1
if count_monday > 0:
print(monday.rstrip(","))
if count_tuesday > 0:
print(tuesday.rstrip(","))
if count_wednesday > 0:
print(wednesday.rstrip(","))
if count_thursday > 0:
print(thursday.rstrip(","))
if count_friday > 0:
print(friday.rstrip(","))
users = [
{"Bill": datetime(year=1986, month=5, day=17)},
{"Jill": datetime(year=1993, month=5, day=17)},
{"Kim": datetime(year=1975, month=5, day=17)},
{"Jan": datetime(year=1969, month=5, day=17)}
]
get_birthdays_per_week(users)