""", self.uid,
)
+ @property
+ def last_promotional_message_sent_at(self):
+ res = self.db.get("""
+ SELECT
+ last_sent_at
+ FROM
+ account_promotional_messages
+ WHERE
+ uid = %s
+ """, self.uid,
+ )
+
+ if res:
+ return res.last_sent_at
+
# Messages
def send_message(self, template, **kwargs):
tasks = {
"accounts:delete" : self.accounts._delete,
"announce-blog-posts" : self.blog.announce,
+ "campaigns:donate" : self.campaigns.donate,
"campaigns:send" : self.campaigns.send,
"check-mirrors" : self.mirrors.check_all,
"cleanup" : self.cleanup,
#!/usr/bin/python3
+import datetime
+
from .misc import Object
class Campaigns(Object):
# Remember that we sent a promotional message
if promotional:
account.promotional_message_sent()
+
+ async def donate(self):
+ """
+ Runs the donation campain, i.e. sends an email once every two months.
+ """
+ t = datetime.datetime.now() - datetime.timedelta(days=60)
+
+ for account in self.backend.accounts.subscribed:
+ # Fall through if we have no timestamp
+ if account.last_promotional_message_sent_at is None:
+ pass
+
+ # Fall through if we have passed the threshold
+ elif account.last_promotional_message_sent_at <= t:
+ pass
+
+ # If nothing matched, we skip this user
+ else:
+ continue
+
+ # Send a donation reminder
+ account.send_message("auth/messages/donation-reminder")
+
+ # Remember that we sent a promotional message
+ account.promotional_message_sent()
# Toot once a day
0 8 * * * nobody sleep ${RANDOM} && ipfire.org --logging=error toot
+# Donation Campaign
+@hourly nobody ipfire.org --logging=error campaigns:donate
+
# Christmas Campaign
0 16 6 12 * nobody ipfire.org --logging=error campaigns:send donate/messages/christmas-1
0 15 17 12 * nobody ipfire.org --logging=error campaigns:send donate/messages/christmas-2