Beispiel #1
0
def remove_unapproved_questions(conn_func, redis_db):
    fields = redis_db.hkeys(ENGLISH_QUESTION_FACTOR_KEY)
    keys_map = dict()
    for field in fields:
        qtype, qid = field.split(':')
        keys_map.setdefault(int(qtype), []).append(field)

    conn = conn_func()
    cursor = conn.cursor()
    count = 0
    for qtype, conf in CONF_MAP.iteritems():
        context_conf = conf['context_conf']
        table = context_conf['table']
        cid = context_conf['cid']
        sql = 'select %s from %s where question_type=%s and state=%s'
        cursor.execute(sql % (cid, table, qtype, K_APPROVED))
        pool = set([qid for qid, in cursor.fetchall()])
        keys = keys_map.get(qtype, [])
        for key in keys:
            qid = int(key.split(':')[1])
            if qid not in pool:
                redis_db.hdel(ENGLISH_QUESTION_FACTOR_KEY, key)
                count += 1
    conn.close()
    print 'remove unapproved english questions: %d' % count
Beispiel #2
0
def remove_unapproved_questions(conn_func, redis_db):
    fields = redis_db.hkeys(ENGLISH_QUESTION_FACTOR_KEY)
    keys_map = dict()
    for field in fields:
        qtype, qid = field.split(':')
        keys_map.setdefault(int(qtype), []).append(field)

    conn = conn_func()
    cursor = conn.cursor()
    count = 0
    for qtype, conf in CONF_MAP.iteritems():
        context_conf = conf['context_conf']
        table = context_conf['table']
        cid = context_conf['cid']
        sql = 'select %s from %s where question_type=%s and state=%s'
        cursor.execute(sql % (cid, table, qtype, K_APPROVED))
        pool = set([qid for qid, in cursor.fetchall()])
        keys = keys_map.get(qtype, [])
        for key in keys:
            qid = int(key.split(':')[1])
            if qid not in pool:
                redis_db.hdel(ENGLISH_QUESTION_FACTOR_KEY, key)
                count += 1
    conn.close()
    print 'remove unapproved english questions: %d' % count
Beispiel #3
0
def remove_unapproved_questions(conn_func, banker_conn_func, redis_db):
    conn = conn_func()
    cursor = conn.cursor()
    banker_conn = banker_conn_func()
    banker_cursor = banker_conn.cursor()
    count = 0
    for qtype, conf in CONF_MAP.iteritems():
        context_conf = conf['context_conf']
        table = context_conf['table']
        cid = context_conf['cid']
        sql = 'select %s from %s where question_type=%s and state=%s'
        banker_cursor.execute(sql % (cid, table, qtype, K_APPROVED))
        pool = set([qid for qid, in banker_cursor.fetchall()])
        keys = redis_db.keys(ENGLISH_QUESTION_FACTOR_KEY % (qtype, '*'))
        for key in keys:
            qid = int(key.split('/')[-1])
            if qid not in pool:
                redis_db.delete(ENGLISH_QUESTION_FACTOR_KEY % (qtype, qid))
                count += 1
    conn.close()
    banker_conn.close()
    print 'remove unapproved questions: %d' % count
Beispiel #4
0
def remove_unapproved_questions(conn_func, banker_conn_func, redis_db):
    conn = conn_func()
    cursor = conn.cursor()
    banker_conn = banker_conn_func()
    banker_cursor = banker_conn.cursor()
    count = 0
    for qtype, conf in CONF_MAP.iteritems():
        context_conf = conf['context_conf']
        table = context_conf['table']
        cid = context_conf['cid']
        sql = 'select %s from %s where question_type=%s and state=%s'
        banker_cursor.execute(sql % (cid, table, qtype, K_APPROVED))
        pool = set([qid for qid, in banker_cursor.fetchall()])
        keys = redis_db.keys(ENGLISH_QUESTION_FACTOR_KEY % (qtype, '*'))
        for key in keys:
            qid = int(key.split('/')[-1])
            if qid not in pool:
                redis_db.delete(ENGLISH_QUESTION_FACTOR_KEY % (qtype, qid))
                count += 1
    conn.close()
    banker_conn.close()
    print 'remove unapproved questions: %d' % count