店播爬取Python脚本

mysql_user_living.py 1.1KB

1234567891011121314151617181920212223242526272829303132
  1. from libs.db_mysql import DbMysql
  2. class MysqlUserLiving(DbMysql):
  3. def __init__(self):
  4. super().__init__()
  5. def get_living_info(self):
  6. sql = 'SELECT `room_id`,l.`uid`,u.`sec_uid` FROM douyin_live as l left join douyin_users as u on l.`uid`=u.`uid` WHERE `finish_time`=0 and `has_commerce_goods`=1 order by l.`sell_count_sum` desc LIMIT 1'
  7. try:
  8. # 查询数据
  9. self.cursor.execute(sql)
  10. return self.cursor.fetchone()
  11. finally:
  12. # 提交到数据库执行
  13. self.db.commit()
  14. # 最终关闭数据库连接
  15. self.cursor.close()
  16. self.db.close()
  17. def get_user_info(self, uid):
  18. sql = 'SELECT `sec_uid` FROM `douyin_users` WHERE `uid`=' + uid
  19. try:
  20. # 查询数据
  21. self.cursor.execute(sql)
  22. return self.cursor.fetchone()
  23. finally:
  24. # 提交到数据库执行
  25. self.db.commit()
  26. # 最终关闭数据库连接
  27. self.cursor.close()
  28. self.db.close()