Exemplo n.º 1
0
    def q_log(self, uid, d):
        m = re.search(r'【(.+)】', d)
        if m:
            q = m.group(1)
            category = 'stock'
            stock = get_stock(q)
            if stock and stock['type'] == 0:
                is_stock = 1
            else:
                is_stock = 0

            sql = 'SELECT * FROM test3 WHERE unionid = %s AND q = %s AND category = %s'
            cur = yield security_pool.execute(sql, (uid, q, category))
            row = cur.fetchone()
            if row:
                sql = 'UPDATE test3 SET counter = counter + 1, is_del = 0, last_visit = NOW() WHERE ' \
                      'unionid = %s AND q = %s AND category = %s'
                yield security_pool.execute(sql, (uid, q, category))
            else:
                sql = 'INSERT INTO test3 VALUES (NULL, %s, %s, %s, 1, NOW(), %s, 0, 0)'
                yield security_pool.execute(sql, (uid, q, category, is_stock))