import time import json import random import dataset #r = redis.Redis(host='db.ptt.cx', port=6379, db=1) #p = r.pubsub(ignore_subscribe_messages=True) db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4') table=db['cur_category'] #cursor=db.query('select id,kw from gtrends where name = "'+site+'" order by rand() limit 1') category='hhh-faq' table.upsert({'category':category,'id':1},keys=['id']) #table.insert({'category':category},)