-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_functions.py
63 lines (47 loc) · 1.78 KB
/
helper_functions.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
57
58
59
60
61
62
63
# Basic encryption method of admin's password
# It is not super secure but it is good enough for our case
def encrypt_password(encrypt):
import hashlib
password = hashlib.sha256()
password = hashlib.sha256(encrypt.encode("utf8")).hexdigest()
return password
def current_month_days():
import calendar
import datetime
today = datetime.date.today()
end_of_month = datetime.date(today.year, today.month, calendar.monthrange(today.year, today.month)[1])
month_days = end_of_month - today
return month_days.days
def start_end_of_week():
import datetime
import calendar
today = datetime.date.today()
start_of_week = today - datetime.timedelta(days=today.weekday())
end_of_week = start_of_week + datetime.timedelta(days=6)
week_days = end_of_week - today
return week_days.days
def calculateDateQuery(option):
from datetime import timedelta
from datetime import date
available_options = {
"today": date.today(),
"tomorrow": date.today() + timedelta(days=1),
"week": date.today() + timedelta(days=start_end_of_week()),
"month": date.today() + timedelta(days=current_month_days()),
}
return available_options[option]
def generateDuties(users_list, option):
from itertools import cycle
from datetime import datetime
from datetime import timedelta
days_list = []
start = calculateDateQuery("today")
end = calculateDateQuery("week")
step = timedelta(days=1)
if option == "month":
end = calculateDateQuery("month")
while start <= end:
days_list.append(start)
start += step
duties_list = list(zip(users_list, cycle(days_list)) if len(users_list) > len(days_list) else zip(cycle(users_list), days_list))
return duties_list