Upload get_next_standup_taker.py
Browse files- get_next_standup_taker.py +33 -0
get_next_standup_taker.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datetime import datetime, timedelta
|
2 |
+
|
3 |
+
team_members = ["Yiannis", "Anastasia", "Bulat", "Thomas", "Sanika"]
|
4 |
+
|
5 |
+
def count_weekdays(start_date, end_date, target_weekdays):
|
6 |
+
total_days = (end_date - start_date).days + 1
|
7 |
+
count = 0
|
8 |
+
|
9 |
+
for day in range(total_days):
|
10 |
+
current_day = start_date + timedelta(days=day)
|
11 |
+
if current_day.weekday() in target_weekdays:
|
12 |
+
count += 1
|
13 |
+
|
14 |
+
return count
|
15 |
+
|
16 |
+
def get_next_standup_taker(last_standup_taker, last_date_str, force_standup_taker=None, current_date=None):
|
17 |
+
today = current_date if current_date else datetime.now().date()
|
18 |
+
today_str = today.strftime("%Y-%m-%d")
|
19 |
+
weekday = today.weekday()
|
20 |
+
|
21 |
+
if weekday not in [1, 3]:
|
22 |
+
return "Today is not a stand-up day.", today_str
|
23 |
+
|
24 |
+
if force_standup_taker:
|
25 |
+
return force_standup_taker, today_str
|
26 |
+
|
27 |
+
last_date = datetime.strptime(last_date_str, "%Y-%m-%d").date()
|
28 |
+
elapsed_days = count_weekdays(last_date, today, [1, 3])
|
29 |
+
last_index = team_members.index(last_standup_taker)
|
30 |
+
next_index = (last_index + elapsed_days - 1) % len(team_members)
|
31 |
+
next_standup_taker = team_members[next_index]
|
32 |
+
|
33 |
+
return next_standup_taker, today_str
|