Example #1
0
 def __call__(self, page_id, cache={}):
     api, cache = get_cache(page_id, cache, API())
     title = cache["title"]
     try:
         p = api.Pages[title]
     except:
         logger.exception("could not find article title: `%s` of type %s in API", title, type(title))
         raise
     if self.date is None:
         revs = p.revisions(dir="older", prop="content")
     if self.before:
         revs = p.revisions(start=self.date_str, dir="older", prop="content")
     else:
         revs = p.revisions(end=self.date_str, dir="newer", prop="content")
     try:
         r = revs.next()
     except StopIteration:
         logger.warning("revisions list is empty for date: %s, before: %s", self.date, self.before)
         r = {"*": ""}
     try:
         content = r["*"]
     except:
         logger.exception("revision object is missing the `*` key. r.keys(): %s", r.keys())
         raise
     return content, cache
Example #2
0
 def __call__(self, page_id, cache={}):
     api, cache = get_cache(page_id, cache, API())
     title = cache['title']
     try:
         p = api.Pages[title]
     except:
         logger.exception('could not find article title: `%s` of type %s in API', title, type(title))
         raise
     if self.date is None:
         revs = p.revisions(dir='older', prop='content')
     if self.before:
         revs = p.revisions(start=self.date_str, dir='older', prop='content')
     else:
         revs = p.revisions(end=self.date_str, dir='newer', prop='content')
     try:
         r = revs.next()
     except StopIteration:
         logger.warning('revisions list is empty for date: %s, before: %s', self.date, self.before)
         r = {'*' : ''}
     try:
         content = r['*']
     except:
         logger.exception('revision object is missing the `*` key. r.keys(): %s', r.keys())
         raise
     return content, cache
Example #3
0
 def __call__(self, page_id, cache={}):
     cur, cache = get_cache(page_id, cache, DB())
     if self.start is None and self.end is None:
         cur.execute("""SELECT rev_user FROM revision WHERE rev_page = %s""", page_id)
     elif self.start is None:
         cur.execute("""SELECT rev_user FROM revision WHERE rev_page = %s AND rev_timestamp < %s""",
                     (page_id, self.end_str))
     elif self.end is None:
         cur.execute("""SELECT rev_user FROM revision WHERE rev_page = %s AND rev_timestamp > %s""",
                     (page_id, self.start_str))
     else:
         cur.execute("""SELECT rev_user FROM revision WHERE rev_page = %s AND rev_timestamp > %s and rev_timestamp < %s""",
                     (page_id, self.start_str, self.end_str))
     res = cur.fetchall()
     user_ids = list(set(map(itemgetter('rev_user'), res)))
     # logger.debug('user_ids:\n%s', user_ids)
     return user_ids, cache
Example #4
0
 def __call__(self, page_id, cache={}):
     start_chars, cache = get_cache(page_id, cache, CharLength(self.start, before=True))
     end_chars, cache = get_cache(page_id, cache, CharLength(self.end, before=True))
     logger.debug("star_chars = %d,\tend_chars = %d", start_chars, end_chars)
     return end_chars - start_chars, cache
Example #5
0
 def __call__(self, page_id, cache={}):
     content, cache = get_cache(page_id, cache, Content(self.date, self.before))
     return len(content), cache
Example #6
0
 def __call__(self, page_id, cache={}):
     editors, cache = get_cache(page_id, cache, Editors(self.start, self.end))
     return len(editors), cache