店播爬取Python脚本

mysql_user_living.py 663B

12345678910111213141516171819
  1. from libs.db_mysql import DbMysql
  2. class MysqlUserLiving(DbMysql):
  3. def __init__(self):
  4. super().__test__()
  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.test.execute(sql)
  10. return self.test.fetchone()
  11. finally:
  12. # 提交到数据库执行
  13. self.db.commit()
  14. # 最终关闭数据库连接
  15. self.test.close()
  16. self.db.close()