Пример #1
0
  def post(self):
    logging.info("chat form: %r" % self.request.form)
    frm = self.request.form.get('from')
    to = self.request.form.get("to")
    txt = self.request.form.get("body")
    jid,res = frm.split('/', 1)
    board = to.split('@')[0]

    if txt == 'SUB':
        sub(jid, board)
        return Response("ya")

    headline = txt[:txt.find('\n')]

    th = re.search('^>>(\d+)', headline)
    if th:
      th = thread_lookup(th.group(1), board)
    else:
      th = re.search('^>>/(\w+)/(\d+)', headline)
      if th:
        board,th = th.groups()
        th = thread_lookup(th, board)
      else:
        th = 'new'

    if not th:
      xmpp.send_message(frm, "WINRY WINRY WINRY", from_jid=to)
      return Response("ya")


    person = {}

    if not antiwipe.check(person, ip=jid, board=board, thread=th):
        xmpp.send_message(frm, "Posted. not really. Keep trying", from_jid=to)
        return Response("ya")

    logging.info('post: %r %r %s' % (board, th, txt))
    #board = 'test'

    args = {
        "text": txt,
        "subject": "",
        "name": "Anonymous",
    }
    post, thread = save_post(self.request, args, board, th, jid)

    MSG = "Posted http://42ch.org/%s/%d/#p%d" %(board, thread, post)

    #
    query = 'board:%s thread:%d' %(board, thread)
    sub_id = '%s/%s/%d' % (jid, board, thread)
    matcher.subscribe(MatchPost, query, sub_id, topic='post')


    xmpp.send_message(frm, MSG, from_jid=to,)

    return Response("ya")
Пример #2
0
 def post(self):
     event = self.request.POST['event']
     datapoint = self.request.POST['datapoint']
     subscription_id = models.StatsSubscription(event=event,
                                                datapoint=datapoint).put()
     prospective_search.subscribe(stats.StatsRecord, 'event:%s' % event,
                                  subscription_id)
     self.response.out.write("Subscribed the datapoint %s to %s events." %
                             (datapoint, event))
Пример #3
0
  def get(self):
    when = int(time.time() + (3600 * 2))

    sub_list = matcher.list_subscriptions(Ep, expires_before=when)

    for sub_id, query, expiration_time, state, error in sub_list:
      matcher.subscribe(Ep, query, sub_id)


    return Response("ok")
Пример #4
0
 def post(self):
   sub = model.Subscription(
       client_id=self.request.POST['client_id'])
   sub.put()
   prospective_search.subscribe(
       model.RequestRecord,
       self.request.POST['query'],
       str(sub.key()),
       lease_duration_sec=config.SUBSCRIPTION_TIMEOUT.seconds)
   self.response.out.write(str(sub.key()))
Пример #5
0
  def post(self, board, thread):
    # FIXME: move subscribe crap somewhere out

    rb = rainbow.make_rainbow(self.request.remote_addr, board, thread)
    person_cookie = self.get_secure_cookie("person", True, max_age=MONTH*12)
    person = person_cookie.get("update", str(uuid()))

    person_cookie['update'] = person

    subid = "%s/%s/%s/%d" %(rb, person, board, thread, )


    token = memcache.get(subid)

    if not token:
      token = channel.create_channel(subid)
      memcache.set(subid, token)

    try:
        query = 'thread:%d board:%s' %(thread, board)

        matcher.subscribe(util.Post, query, subid,
        topic='post',
        lease_duration_sec=self.WATCH_TIME)
    except OverQuotaError:
        logging.error("subscribe failed")
        token = None

    post_level = util.post_level(self.request.remote_addr)

    """
    if self.NEWFAG and \
      not person_cookie.get("postcount") > self.OLDFAG and \
      (board, thread) not in self.NEWFAG:
          post_level = "err"
    """


    return json_response( 
        {
          "token" : token,
          "post_quota" : post_level,
          "watcher_time" : self.WATCH_TIME,
        }
    )
Пример #6
0
def create_query_and_subscribe(topic, query, channel_id):
    saved_query = RssSearchSubscription(query=query, topic=topic)
    yield saved_query.put_async()

    raise ndb.Return(
        prospective_search.subscribe(RssItem,
                                     saved_query.query,
                                     saved_query.urlsafe(),
                                     topic=topic,
                                     lease_duration_sec=0))
Пример #7
0
def subscribe_user_for_nearby_questions(prospective_user_id):
    """Create new subscriptions for the provided question and user."""
    active_subscriptions = ProspectiveSubscription.get_for(prospective_user_id)
    sub = active_subscriptions.get()
    if sub is None:
        sub = ProspectiveSubscription(
            prospective_user_id=prospective_user_id
        )
        sub.put()

    prospective_user = ProspectiveUser.get_by_id(prospective_user_id)
    # nearby_question = NearbyQuestion.get_by_id(nearby_question_id)
    # query = 'origin_latitude = {:f} AND origin_longitude = {:f} AND origin_distance_in_km < {:d}'\
    #     .format(prospective_user.origin_location.lat, prospective_user.origin_location.lon, prospective_user.notification_radius_in_km)

    query = 'origin_distance_in_km < {:d}'.format(prospective_user.notification_radius_in_km)

    # "Topics are not defined as a separate step; instead, topics are created as a side effect of the subscribe() call."
    prospective_search.subscribe(
        NearbyQuestion,
        query,
        str(sub.key.id()),
        lease_duration_sec=300
    )
Пример #8
0
def subscribe(document_class,
              query,
              sub_id,
              schema=None,
              topic=None,
              lease_duration_sec=DEFAULT_LEASE_DURATION_SEC):
    """Subscribe a query."""
    assert schema is None
    topic = _get_document_topic(document_class, topic)
    schema = _model_to_entity_schema(document_class)
    return prospective_search.subscribe(datastore.Entity,
                                        query,
                                        sub_id,
                                        schema=schema,
                                        topic=topic,
                                        lease_duration_sec=lease_duration_sec)
Пример #9
0
def subscribe(document_class,
              query,
              sub_id,
              schema=None,
              topic=None,
              lease_duration_sec=DEFAULT_LEASE_DURATION_SEC):
  """Subscribe a query."""
  assert schema is None
  topic = _get_document_topic(document_class, topic)
  schema = _model_to_entity_schema(document_class)
  return prospective_search.subscribe(
    datastore.Entity,
    query,
    sub_id,
    schema=schema,
    topic=topic,
    lease_duration_sec=lease_duration_sec)
Пример #10
0
  def get(self, title):
    user = get_current_user()
    sub_id = "%s/%s" % (user.email(), title)
    matcher.subscribe(Ep, "title:"+title, sub_id)

    return redirect_to("title", title=title)
Пример #11
0
def sub(jid, board):
    subid = '%s/%s' % (jid, board)
    query = 'board:%s thread_flag:new' % (board,)
    matcher.subscribe(MatchPost, query, subid, topic='post')
Пример #12
0
 def post(self):
     event = self.request.POST["event"]
     datapoint = self.request.POST["datapoint"]
     subscription_id = models.StatsSubscription(event=event, datapoint=datapoint).put()
     prospective_search.subscribe(stats.StatsRecord, "event:%s" % event, subscription_id)
     self.response.out.write("Subscribed the datapoint %s to %s events." % (datapoint, event))
Пример #13
0
def create_query_and_subscribe(topic, query, channel_id):
    saved_query = RssSearchSubscription(query=query, topic=topic)
    yield saved_query.put_async()

    raise ndb.Return(prospective_search.subscribe(RssItem, saved_query.query, saved_query.urlsafe(), topic=topic, lease_duration_sec=0))