Пример #1
0
  def post(self):

    post = matcher.get_document(self.request.form)
    send = post.data

    for sub_id in self.request.form.getlist('id'):
      logging.info("send post to %s" % sub_id)

      if send.get('evt') == 'online' and '@' in sub_id:
        continue

      if '@' in sub_id:
        jid = sub_id.split('/')[0]
        whoami = '%(board)[email protected]' % send
        MSG = """Posted http://42ch.org/%(board)s/%(thread)d/#p%(last)d\n\n%(text)s""" % send
        xmpp.send_message(jid, MSG, from_jid=whoami)
        continue

      try:
        channel.send_message(sub_id, dumps(send))
      except channel.InvalidChannelClientIdError:
        logging.error("inval client id %r" % sub_id)
      except channel.InvalidMessageError:
        logging.error("inval msg: %r" % dumps(send))

    return Response("ok")
Пример #2
0
def match_prospective_search():
    """Callback on prospective search match."""
    if request.method == "POST":
        logging.info("received a match")
        webapp2Request = request.form
        nearby_question = prospective_search.get_document(webapp2Request)
        prospective_user = ProspectiveUser.get_by_id(nearby_question.for_prospective_user_id)
        question = Question.get_by_id(nearby_question.for_question_id)

        notify_new_question(prospective_user.login, question)
    return '', 200
Пример #3
0
 def post(self):
     record = prospective_search.get_document(self.request)
     record_value = simplejson.loads(record.value)
     subscriber_keys = map(db.Key, self.request.get_all("id"))
     subscribers = db.get(subscriber_keys)
     datapoints = []
     stats_json = []
     for subscriber_key, subscriber in zip(subscriber_keys, subscribers):
         if not subscriber:
             prospective_search.unsubscribe(stats.StatsRecord, subscriber_key)
         else:
             datapoints.append(models.getStats(subscriber.datapoint, record.timestamp, duration="day"))
             datapoints.append(models.getStats(subscriber.datapoint, record.timestamp, duration="hour"))
     for datapoint in datapoints:
         if datapoint.datapoint == "active_users":
             try:
                 user = models.getUser(record_value["user"], False)
             except models.UserDoesNotExistError:
                 continue
             last_seen = user.last_seen
             new_last_seen = timestamp.now()
             if datapoint.duration == "day":
                 last_seen = last_seen.replace(hour=0, minute=0, second=0, microsecond=0)
                 new_last_seen = new_last_seen.replace(hour=0, minute=0, second=0, microsecond=0)
             if last_seen < new_last_seen:
                 user.updateLastSeen(new_last_seen)
                 user.save()
             else:
                 continue
         if datapoint.datapoint == "quota":
             datapoint.count = models.getQuota().amount
         else:
             datapoint.increment()
         json = {
             "datapoint": datapoint.datapoint,
             "value": datapoint.count,
             "date": datapoint.date.strftime("%D, %M %d %y"),
             "datestamp": int(time.mktime(datapoint.date.date().timetuple())) * 1000,
             "hour": datapoint.date.hour,
         }
         if datapoint.duration == "day":
             json["hour"] = "total"
         stats_json.append(json)
     db.put(datapoints)
     push = channels.Channel("[email protected]/Web", False)
     push.message = {"stats": stats_json}
     push.send()
     logging.debug(simplejson.dumps(stats_json))
Пример #4
0
def inbound_search_matches():
    if request.headers.get('X-Appengine-Queuename') != 'default':
        raise ndb.Return(jsonify_error(message='Not a cron call'))

    # List of subscription ids that matched for match.
    sub_ids = request.form.getlist('id')
    keys = []
    for sub_id in sub_ids:
        keys.append(ndb.Key(urlsafe=sub_id))

    subs = yield ndb.get_multi_async(keys)
    doc = prospective_search.get_document(request.form)
    for sub in subs:
        logger.info('prospective: Would have sent to %s %s', sub, doc)

    logger.info('prospective: Request form: %s', request.form)
    raise ndb.Return(jsonify(status='ok'))
Пример #5
0
def inbound_search_matches():
    if request.headers.get('X-Appengine-Queuename') != 'default':
        raise ndb.Return(jsonify_error(message='Not a cron call'))

    # List of subscription ids that matched for match.
    sub_ids = request.form.getlist('id')
    keys = []
    for sub_id in sub_ids:
        keys.append(ndb.Key(urlsafe=sub_id))

    subs = yield ndb.get_multi_async(keys)
    doc = prospective_search.get_document(request.form)
    for sub in subs:
        logger.info('prospective: Would have sent to %s %s', sub, doc)

    logger.info('prospective: Request form: %s', request.form)
    raise ndb.Return(jsonify(status='ok'))
Пример #6
0
  def post(self):
    # Fetch the log record
    record = prospective_search.get_document(self.request)
    record_data = record.to_json()

    # Fetch the set of subscribers to send this record to
    subscriber_keys = map(db.Key, self.request.get_all('id'))
    subscribers = db.get(subscriber_keys)

    for subscriber_key, subscriber in zip(subscriber_keys, subscribers):
      # If the subscription has been deleted from the datastore, delete it
      # from the matcher API.
      if not subscriber:
        logging.error("Subscription %s deleted!", subscriber_key)
        prospective_search.unsubscribe(model.RequestRecord, subscriber_key)
      else:
        data = simplejson.dumps({
            'subscription_key': str(subscriber_key),
            'data': record_data,
        })
        channel.send_message(subscriber.client_id, data)
Пример #7
0
 def post(self):
     record = prospective_search.get_document(self.request)
     record_value = simplejson.loads(record.value)
     subscriber_keys = map(db.Key, self.request.get_all('id'))
     subscribers = db.get(subscriber_keys)
     datapoints = []
     stats_json = []
     for subscriber_key, subscriber in zip(subscriber_keys, subscribers):
         if not subscriber:
             prospective_search.unsubscribe(stats.StatsRecord,
                                            subscriber_key)
         else:
             datapoints.append(
                 models.getStats(subscriber.datapoint,
                                 record.timestamp,
                                 duration='day'))
             datapoints.append(
                 models.getStats(subscriber.datapoint,
                                 record.timestamp,
                                 duration='hour'))
     for datapoint in datapoints:
         if datapoint.datapoint == 'active_users':
             try:
                 user = models.getUser(record_value['user'], False)
             except models.UserDoesNotExistError:
                 continue
             last_seen = user.last_seen
             new_last_seen = timestamp.now()
             if datapoint.duration == "day":
                 last_seen = last_seen.replace(hour=0,
                                               minute=0,
                                               second=0,
                                               microsecond=0)
                 new_last_seen = new_last_seen.replace(hour=0,
                                                       minute=0,
                                                       second=0,
                                                       microsecond=0)
             if last_seen < new_last_seen:
                 user.updateLastSeen(new_last_seen)
                 user.save()
             else:
                 continue
         if datapoint.datapoint == 'quota':
             datapoint.count = models.getQuota().amount
         else:
             datapoint.increment()
         json = {
             'datapoint': datapoint.datapoint,
             'value': datapoint.count,
             'date': datapoint.date.strftime("%D, %M %d %y"),
             'datestamp':
             int(time.mktime(datapoint.date.date().timetuple())) * 1000,
             'hour': datapoint.date.hour
         }
         if datapoint.duration == "day":
             json['hour'] = "total"
         stats_json.append(json)
     db.put(datapoints)
     push = channels.Channel("[email protected]/Web", False)
     push.message = {"stats": stats_json}
     push.send()
     logging.debug(simplejson.dumps(stats_json))