]> git.ipfire.org Git - ipfire.org.git/commitdiff
blog+tweets: Allow passing different times to recent activity functions
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 23 Oct 2019 13:37:06 +0000 (14:37 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 23 Oct 2019 13:37:06 +0000 (14:37 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/blog.py
src/backend/tweets.py

index 094a565ffbfac2bb65786127195cbd9598feb3f1..c66cc37aea9670f3d4331be51c12d87b12e94551 100644 (file)
@@ -88,9 +88,8 @@ class Blog(misc.Object):
                                ORDER BY ts_rank(search_index.document, to_tsquery('english', %s)) DESC \
                        LIMIT %s", query, query, limit)
 
-       def has_had_recent_activity(self, t=None):
-               if t is None:
-                       t = datetime.timedelta(hours=24)
+       def has_had_recent_activity(self, **kwargs):
+               t = datetime.timedelta(**kwargs)
 
                res = self.db.get("SELECT COUNT(*) AS count FROM blog \
                        WHERE published_at IS NOT NULL AND published_at >= NOW() - %s", t)
index 11370427d38da6e1525a64452030b7831a6e3072..543fcdf25f1adb35026ec40b389f5fa758817ea1 100644 (file)
@@ -14,12 +14,12 @@ class Tweets(Object):
                        Sends a random promotional tweet
                """
                # Do not tweet too often
-               if self.has_had_recent_activity():
+               if self.has_had_recent_activity(days=4):
                        logging.debug("Won't tweet because we recently did it")
                        return
 
                # Do not tweet when there was a blog post
-               if self.backend.blog.has_had_recent_activity():
+               if self.backend.blog.has_had_recent_activity(hours=24):
                        logging.debug("Won't tweet because the blog has had activity")
                        return
 
@@ -33,9 +33,8 @@ class Tweets(Object):
                with self.db.transaction():
                        self._tweet(tweet)
 
-       def has_had_recent_activity(self, t=None):
-               if t is None:
-                       t = datetime.timedelta(days=4)
+       def has_had_recent_activity(self, **kwargs):
+               t = datetime.timedelta(**kwargs)
 
                res = self.db.get("SELECT COUNT(*) AS count FROM tweets \
                        WHERE last_tweeted_at IS NOT NULL AND last_tweeted_at >= NOW() - %s", t)