店播爬取Python脚本

mysql_dy_live_ifsolt.py 621B

123456789101112131415161718
  1. from libs.db_mysql import DbMysql
  2. class MysqlDyLiveCommodity(DbMysql):
  3. table = 'douyin_live_commodity_'
  4. # 获取直播数据
  5. def get_goods_info(self, room_id, product_id, pix):
  6. sql = 'SELECT id,sold_out_at,revise_price,created_at FROM ' + self.table + pix + ' WHERE `room_id`=%s and `product_id`=%s LIMIT 1'
  7. try:
  8. # 执行SQL
  9. self.cursor.execute(sql, [room_id, product_id])
  10. return self.cursor.fetchone()
  11. finally:
  12. self.db.commit() # 提交
  13. self.cursor.close() # 关闭cursor
  14. self.db.close() # 关闭db连接