From: Michael Tremer Date: Wed, 23 Oct 2019 13:37:06 +0000 (+0100) Subject: blog+tweets: Allow passing different times to recent activity functions X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9268f3c38d92d071239b65e1e9d59fd105651079;p=ipfire.org.git blog+tweets: Allow passing different times to recent activity functions Signed-off-by: Michael Tremer --- diff --git a/src/backend/blog.py b/src/backend/blog.py index 094a565f..c66cc37a 100644 --- a/src/backend/blog.py +++ b/src/backend/blog.py @@ -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) diff --git a/src/backend/tweets.py b/src/backend/tweets.py index 11370427..543fcdf2 100644 --- a/src/backend/tweets.py +++ b/src/backend/tweets.py @@ -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)