]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/backend/blog.py
Add bot that automatically tweets some things
[ipfire.org.git] / src / backend / blog.py
index 034fd4c1d5579697384460ebf04b8720aa7a8438..e79dd308f2cad6ae5352b8185ff8ff9e3ff25ce8 100644 (file)
@@ -5,9 +5,11 @@ import feedparser
 import markdown2
 import re
 import textile
+import tornado.gen
 import unicodedata
 
 from . import misc
+from . import util
 from .decorators import *
 
 # Used to automatically link some things
@@ -88,7 +90,7 @@ class Blog(misc.Object):
                        ORDER BY COALESCE(updated_at, created_at) DESC LIMIT %s", limit)
 
        def search(self, query, limit=None):
-               query = self._parse_search_query(query)
+               query = util.parse_search_query(query)
 
                return self._get_posts("SELECT blog.* FROM blog \
                        LEFT JOIN blog_search_index search_index ON blog.id = search_index.post_id \
@@ -96,24 +98,17 @@ class Blog(misc.Object):
                                ORDER BY ts_rank(search_index.document, to_tsquery('english', %s)) DESC \
                        LIMIT %s", query, query, limit)
 
-       def _parse_search_query(self, query):
-               q = []
-               for word in query.split():
-                       # Is this lexeme negated?
-                       negated = word.startswith("!")
+       def has_had_recent_activity(self, t=None):
+               if t is None:
+                       t = datetime.timedelta(hours=24)
 
-                       # Remove any special characters
-                       word = re.sub(r"\W+", "", word, flags=re.UNICODE)
-                       if not word:
-                               continue
+               res = self.db.get("SELECT COUNT(*) AS count FROM blog \
+                       WHERE published_at IS NOT NULL AND published_at >= NOW() - %s", t)
 
-                       # Restore negation
-                       if negated:
-                               word = "!%s" % word
+               if res and res.count > 0:
+                       return True
 
-                       q.append(word)
-
-               return " & ".join(q)
+               return False
 
        def create_post(self, title, text, author, tags=[], lang="markdown"):
                """
@@ -181,6 +176,7 @@ class Blog(misc.Object):
                for row in res:
                        yield row.year
 
+       @tornado.gen.coroutine
        def update_feeds(self):
                """
                        Updates all enabled feeds