mysql_to_redis.py 1.1 KB

123456789101112131415161718
  1. import dataset
  2. import pymysql
  3. pymysql.install_as_MySQLdb()
  4. import redis
  5. import json
  6. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  7. table=db['selected_kw']
  8. lst = []
  9. cur = db.query('select term,url from seo.sns_kw where client="loginheart"')
  10. for c in cur:
  11. lst.append([c['term'],c['url']])
  12. print(lst)
  13. # r = redis.Redis(host='db.ptt.cx', port=6379, db=1,password='choozmo9')
  14. # r.set(lst)
  15. ['真皮迷你包', 'https://www.zeczec.com/projects/loginheart'], ['小廢包 品牌', 'https://www.zeczec.com/projects/loginheart'], ['電子支付包包', 'https://www.zeczec.com/projects/loginheart'], ['感應支付 小包包', 'https://www.zeczec.com/projects/loginheart'], ['一卡通小包', 'https://www.zeczec.com/projects/loginheart'], ['迷你包 推薦', 'https://www.zeczec.com/projects/loginheart'], ['科技 小廢包', 'https://www.zeczec.com/projects/loginheart'], ['小配方包', 'https://www.zeczec.com/projects/loginheart'], ['精品包包', 'https://www.zeczec.com/projects/loginheart'], ['時尚科技 台灣 包包品牌', 'https://www.zeczec.com/projects/loginheart']