コード例 #1
0
ファイル: exporter.py プロジェクト: opaquebox/TAnon
import time
import datetime
import os

from lib.model import sm
from lib.export import export_chat

if __name__ == '__main__':

    if not os.path.exists("logs"):
        os.makedirs("logs")

    redis = Redis(host=os.environ['REDIS_HOST'],
                  port=int(os.environ['REDIS_PORT']),
                  db=int(os.environ['REDIS_DB']))
    sql = sm()

    current_time = datetime.datetime.now()

    while True:
        if datetime.datetime.now().minute != current_time.minute:
            # Export chats.
            for chat in redis.smembers('export-queue'):
                export_chat(redis, sql, chat)
                redis.srem('export-queue', chat)
                redis.set('chat.' + chat + '.exported', 1)
                redis.expire('chat.' + chat + '.exported',
                             86400)  # 86400 seconds = 1 day

        current_time = datetime.datetime.now()
コード例 #2
0
        return v
    return defaultValue

if __name__=='__main__':

    redis = Redis(host=os.environ['REDIS_HOST'], port=int(os.environ['REDIS_PORT']), db=int(os.environ['REDIS_DB']))

    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.
コード例 #3
0
ファイル: reaper.py プロジェクト: xalgorithm/MSPARP
                    ]
                disconnect_message = (
                    "%s's connection timed out. Please don't quit straight away; they could be back." % (session_name)
                )
            disconnect(redis, chat, session, disconnect_message)
            print "dead", dead

        for dead in redis.zrangebyscore("searchers", 0, get_time()):
            print "reaping searcher", dead
            redis.zrem("searchers", dead)

        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()
コード例 #4
0
ファイル: exporter.py プロジェクト: MSPARP/MSPARP
from redis import Redis
import time
import datetime
import os

from lib.model import sm
from lib.export import export_chat

if __name__ == '__main__':

    if not os.path.exists("logs"):
        os.makedirs("logs")

    redis = Redis(host=os.environ['REDIS_HOST'], port=int(os.environ['REDIS_PORT']), db=int(os.environ['REDIS_DB']))
    sql = sm()

    current_time = datetime.datetime.now()

    while True:
        if datetime.datetime.now().minute != current_time.minute:
            # Export chats.
            for chat in redis.smembers('export-queue'):
                export_chat(redis, sql, chat)
                redis.srem('export-queue', chat)
                redis.set('chat.' + chat + '.exported', 1)
                redis.expire('chat.' + chat + '.exported', 86400)  # 86400 seconds = 1 day

        current_time = datetime.datetime.now()

        time.sleep(1)