Ejemplo n.º 1
0
def save_log():
    if not validate_chat_url(request.form['chat']):
        abort(400)
    chat_type = g.redis.hget('chat.'+request.form['chat']+'.meta', 'type')
    if chat_type not in ['unsaved', 'saved']:
        abort(400)
    log_id = archive_chat(g.redis, g.mysql, request.form['chat'])
    g.redis.hset('chat.'+request.form['chat']+'.meta', 'type', 'saved')
    g.redis.zadd('archive-queue', request.form['chat'], get_time(ARCHIVE_PERIOD))
    if 'tumblr' in request.form:
        # Set the character list as tags.
        tags = g.redis.smembers('chat.'+request.form['chat']+'.characters')
        tags.add('msparp')
        url_tags = urllib.quote_plus(','.join(tags))
        return redirect('http://www.tumblr.com/new/link?post[one]=Check+out+this+chat+I+just+had+on+MSPARP!&post[two]=http%3A%2F%2Funsupported.msparp.com%2Flogs%2F'+str(log_id)+'&post[source_url]=http%3A%2F%2Fmsparp.com%2F&tags='+url_tags)
    return redirect(url_for('view_log', chat=request.form['chat']))
Ejemplo n.º 2
0
        new_time = datetime.datetime.now()

        # Every minute
        if new_time.minute != current_time.minute:
            mysql = sm()

            # Send blank messages to avoid socket timeouts.
            for chat in redis.zrangebyscore("longpoll-timeout", 0, get_time()):
                send_message(redis, chat, -1, "message")

            # Expire IP bans.
            redis.zremrangebyscore("ip-bans", 0, get_time())

            # Archive chats.
            for chat in redis.zrangebyscore("archive-queue", 0, get_time()):
                archive_chat(redis, mysql, chat, 50)
                pipe = redis.pipeline()
                pipe.scard("chat." + chat + ".online")
                pipe.scard("chat." + chat + ".idle")
                online, idle = pipe.execute()
                # Stop archiving if no-one is online any more.
                if online + idle == 0:
                    redis.zrem("archive-queue", chat)
                else:
                    redis.zadd("archive-queue", chat, get_time(ARCHIVE_PERIOD))

            # Delete chat-sessions.
            for chat_session in redis.zrangebyscore("chat-sessions", 0, get_time()):
                delete_chat_session(redis, *chat_session.split("/"))

            # Delete chats.
Ejemplo n.º 3
0
        # Every minute
        if new_time.minute!=current_time.minute:
            mysql = sm()

            # Send blank messages to avoid socket timeouts.
            for chat in redis.zrangebyscore('longpoll-timeout', 0, get_time()):
                send_message(redis, chat, -1, "message")

            # Expire IP bans.
            redis.zremrangebyscore('ip-bans', 0, get_time())

            # Archive chats.
            for chat in redis.zrangebyscore('archive-queue', 0, get_time()):
                try:
                    archive_chat(redis, mysql, chat)
                except (sqlalchemy.exc.IntegrityError, sqlalchemy.exc.ProgrammingError):
                    redis = redis = Redis(unix_socket_path='/tmp/redis.sock')
                    mysql = sm()
                    pass
                pipe = redis.pipeline()
                pipe.scard('chat.'+chat+'.online')
                pipe.scard('chat.'+chat+'.idle')
                online, idle = pipe.execute()
                # Delete if no-one is online any more.
                if online+idle==0:
                    delete_chat(redis, mysql, chat)
                    redis.zrem('archive-queue', chat)
                else:
                    redis.zadd('archive-queue', chat, get_time(ARCHIVE_PERIOD))
Ejemplo n.º 4
0
    current_time = datetime.datetime.now()

    while True:

        new_time = datetime.datetime.now()

        # Every minute
        if new_time.minute!=current_time.minute:
            mysql = sm()
            
            # Expire IP bans.
            redis.zremrangebyscore('ip-bans', 0, get_time())

            # Archive chats.
            for chat in redis.zrangebyscore('archive-queue', 0, get_time()):
                archive_chat(redis, mysql, chat, 0)
                online = redis.scard('chat.'+chat+'.online')
                # Stop archiving if no-one is online any more.
                if online == 0:
                    redis.zrem('archive-queue', chat)
                else:
                    redis.zadd('archive-queue', chat, get_time(ARCHIVE_PERIOD))

            # Delete chat-sessions.
            for chat_session in redis.zrangebyscore('chat-sessions', 0, get_time()):
                delete_chat_session(redis, *chat_session.split('/'))

            # Delete chats.
            for chat in redis.zrangebyscore('delete-queue', 0, get_time()):
                delete_chat(redis, mysql, chat)