Beispiel #1
0
  def ref_post(self, post_id):
    ret_str = ''
    logging.info('ref_post called with id: ' + post_id)
    try:
      post = self.client.post(post_id).data
      ref = lib.referee.Referee(post)
      decision = ref.referee_decision
      if decision is not None:
        # post here
        try:
          new_comment = buzz.Comment(content=decision, post_id=post_id)
          self.client.create_comment(new_comment)

          # cache this decision
          pid = str(post.id[25:])
          if DecisionCache.get_by_key_name(pid) is None:
            new_decision = DecisionCache(key_name=pid)
            new_decision.winner_id = str(ref.winner.id)
            new_decision.put()

          ret_str = "Writing comment: " + decision + "<br />" + \
              "to post.id = " + post.id
        except:
          ret_str = "<h2>Error:</h2><br />" + "Writing comment: " + \
              decision + "<br />" + "to post.id = " + post.id + \
              "<br />" + "<pre>"  + traceback.format_exc()  + "</pre>"
    except:
      ret_str = "<h2>Error:</h2><br />" + "Getting post: " + post_id + \
          "<br />" + "<pre>"  + traceback.format_exc()  + "</pre>"

    logging.info('returning: ' + ret_str)
    return ret_str
Beispiel #2
0
  def referee_decision(self):
    if not hasattr(self, '_ref_decision') or not self._ref_decision:
      attributes = lib.post_attributes.PostAttributes(self.post)

      comments = self.post.comments()
      
      comments_list = []
      for comment in comments:
        attributes.update_attributes(comment)
        comments_list.append(comment)

      if len(comments_list) > 0:
        attributes.set('last', comments_list[-1].actor.id)
      else:
        attributes.set('last', self.post.actor.id)

      attributes.finalize_attributes()

      winner_id = random.choice(attributes.commenters.keys())
      self.winner = attributes.commenters_o[winner_id]

      self._ref_decision = self.build_referee_decision(attributes)
      if self._ref_decision == '' or self._ref_decision == None:
        self._ref_decision = None
        # cache this post as already decided on
        pid = str(self.post.id[25:])
        if DecisionCache.get_by_key_name(pid) is None:
          new_decision = DecisionCache(key_name=pid)
          new_decision.put()
    return self._ref_decision
Beispiel #3
0
  def queue_ref(self):
    # get consumption posts
    posts = self.client.posts(type_id='@consumption', user_id='@me', max_results=5000).data

    ret_str = '#posts: ' + str(len(posts)) + '<br />'

    for post in posts:
      
      if DecisionCache.get_by_key_name(str(post.id[25:])) is None and \
          post.placeholder is None and \
          post.actor.id != utils.consts.BUZZREFEREE_ID:
        try:
          result_task = taskqueue.Task(
            name="%s-%d" % (post.id[25:], int(time.time())),
            params={
              'post_id': post.id
            },
            url='/ref',
            countdown=1
          )
          result_task.add()
          ret_str += 'Added post id: ' + post.id + '<br />'
        except:
          result_task = None
          ret_str += 'taskqueue exception<br />'

    return ret_str