"""
Sends a random promotional toot
"""
- # Do not toot too often
- if self.has_had_recent_activity(days=3):
- logging.debug("Won't toot because we recently did it")
- return
-
# Do not toot when there was a blog post
if self.backend.blog.has_had_recent_activity(hours=24):
logging.debug("Won't toot because the blog has had activity")
with self.db.transaction():
self._toot(toot)
- def has_had_recent_activity(self, **kwargs):
- t = datetime.timedelta(**kwargs)
-
- res = self.db.get("SELECT COUNT(*) AS count FROM toots \
- WHERE last_tooted_at IS NOT NULL AND last_tooted_at >= NOW() - %s", t)
-
- if res and res.count > 0:
- return True
-
- return False
-
def _get_random_toot(self):
res = self.db.get(
"WITH candidate_toots AS (SELECT id, \