-
Notifications
You must be signed in to change notification settings - Fork 0
/
membership_handling.py
90 lines (75 loc) · 3.3 KB
/
membership_handling.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from podio_api import PodioAPI
from misc import gen_random_password
from user import User
from mail import MailSender
from ascii import translate_to_ascii
from datetime import datetime
import json, math, time
# Sends reminder email to members that haven't paid their membership fee.
def remind_members():
podio = PodioAPI("podio.json")
mail_sender = MailSender("mail.json")
print("Fetching members from podio ...")
all_members = podio.get_all_members()
print("done.")
print(f"Got {len(all_members)} members.")
if len(all_members) == 0:
print("No members found. Major ERROR")
return
current_time = datetime.now()
members_which_need_to_be_reminded = []
statistics = {"members": 0, "total": 0, "high_payers": []}
for member in all_members:
payed_until = datetime.strptime(
podio.get_start_of_field_with_id(229789505, member), "%Y-%m-%d %H:%M:%S"
)
if not current_time <= payed_until:
amount = math.ceil((current_time - payed_until).days / (6 * 30)) * 25
print(
f"{(current_time-payed_until).days} days not payed for {podio.get_value_of_field_with_id(206982184, member)} = {amount}€"
)
member.update({"days_not_payed": (current_time - payed_until).days})
member.update({"amount": amount})
members_which_need_to_be_reminded.append(member)
given_name = podio.get_value_of_field_with_id(206982183, member)
surname = podio.get_value_of_field_with_id(206982184, member)
statistics["members"] += 1
statistics["total"] += amount
if amount > 70:
statistics["high_payers"].append((given_name + " " + surname, amount))
statistics["high_payers"].sort(key=lambda p: p[1], reverse=True)
statistc_msg = f"{statistics['members']} received a membership payment reminder, totalling in about €{statistics['total']}.\n"
if len(statistics["high_payers"]) == 0:
statistc_msg += "There are no worrisome members \(^.^)/"
else:
statistc_msg += "The most worrisome members are:\n"
statistc_msg += "".join(
map(lambda hp: f"* {hp[0]}: {hp[1]}€\n", statistics["high_payers"])
)
mail_sender.send_plain_email(
"Member reminder statistics", statistc_msg, "hr@spaceteam.at"
)
print(f"Sending {len(members_which_need_to_be_reminded)} reminders.")
for member in members_which_need_to_be_reminded:
if member is None:
continue
given_name = podio.get_value_of_field_with_id(206982183, member)
surname = podio.get_value_of_field_with_id(206982184, member)
recovery_email = podio.get_value_of_field_with_id(206982186, member)
podio_id = member["item_id"]
user = User(
email=translate_to_ascii(given_name.lower() + "." + surname.lower())
+ "@spaceteam.at",
recovery_email=recovery_email,
given_name=given_name,
family_name=surname,
password="",
)
print(f"Sending mail reminder ({given_name} {surname}) ...")
mail_sender.send_reminder_email(
user, member["amount"], member["days_not_payed"]
)
time.sleep(3)
print("done.")
if __name__ == "__main__":
remind_members()