Пример #1
0
 def raw_log(self,q):
     time = datetime.datetime.now()
     timestr = '{}.{}'.format(time.strftime('%Y-%m-%d %H:%M:%S'), time.microsecond)
     ip = self.request.headers.get("X-Forwarded-For") or self.request.headers.get("X-Real-IP") or \
         self.request.remote_ip
     useragent = self.request.headers.get('User-Agent', 'Unknown')
     sql = 'INSERT INTO test1 VALUES (NULL, %s, %s, %s, %s)'
     yield security_pool.execute(sql,(timestr,ip,useragent,q))
Пример #2
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))