]> git.ipfire.org Git - ipfire.org.git/blob - src/backend/campaigns.py
816e02e57e4c19238f5f812b30bf2e163beb3ad4
[ipfire.org.git] / src / backend / campaigns.py
1 #!/usr/bin/python3
2
3 import datetime
4
5 from .misc import Object
6
7 class Campaigns(Object):
8 async def send(self, template, promotional=True, **kwargs):
9 """
10 Sends a message to all users that have consented to promotional messages
11 """
12 for account in self.backend.accounts.subscribed:
13 # Send the message
14 account.send_message(template, **kwargs)
15
16 # Remember that we sent a promotional message
17 if promotional:
18 account.promotional_message_sent()
19
20 async def donate(self):
21 """
22 Runs the donation campain, i.e. sends an email once every two months.
23 """
24 t = datetime.datetime.now() - datetime.timedelta(days=60)
25
26 for account in self.backend.accounts.subscribed:
27 # Fall through if we have no timestamp
28 if account.last_promotional_message_sent_at is None:
29 pass
30
31 # Fall through if we have passed the threshold
32 elif account.last_promotional_message_sent_at <= t:
33 pass
34
35 # If nothing matched, we skip this user
36 else:
37 continue
38
39 # Send a donation reminder
40 account.send_message("auth/messages/donation-reminder")
41
42 # Remember that we sent a promotional message
43 account.promotional_message_sent()