DataSearchUtils.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import pymysql
  2. class MysqlSearchUtils():
  3. def __init__(self):
  4. try:
  5. self.conn = pymysql.connect(host="139.186.27.96",port=4000,user="data",passwd="hcst@2021",db="jeecg-boot",charset="utf8mb4")
  6. self.cursor = self.conn.cursor()
  7. except pymysql.err as e:
  8. print("error"% e)
  9. def get_one(self):
  10. sql = "select * from ctop_user_allocation where account_id = %s order by id desc"
  11. self.cursor.execute(sql, ('9556344',))
  12. rest = self.cursor.fetchone()
  13. result = dict(zip([k[0] for k in self.cursor.description], rest))
  14. self.cursor.close()
  15. return result
  16. def get_all(self):
  17. sql = "select * from ctop_user_allocation where project_id = %s order by id desc"
  18. self.cursor.execute(sql, ('458',))
  19. rest = self.cursor.fetchall()
  20. result = [dict(zip([k[0] for k in self.cursor.description], row)) for row in rest]
  21. self.cursor.close()
  22. return result
  23. def get_all_ai_account_target_template_by_params(self,status,account_id):
  24. sql = "select * from ctop_ai_kuaishou_auto_creative_account_info where status = %s order by id desc"
  25. self.cursor.execute(sql, (status,))
  26. rest = self.cursor.fetchall()
  27. result = [dict(zip([k[0] for k in self.cursor.description], row)) for row in rest]
  28. self.cursor.close()
  29. return result
  30. def db_close(self):
  31. self.conn.close()
  32. def get_kuaishou_video_list_by_params(self, accountId, startDate, endDate):
  33. sql = "select * from ctop_kuaishou_video_get where account_id = %s and stat_date>= %s and stat_date<=%s order by id desc"
  34. self.cursor.execute(sql, (accountId,startDate,endDate))
  35. rest = self.cursor.fetchall()
  36. result = [dict(zip([k[0] for k in self.cursor.description], row)) for row in rest]
  37. self.cursor.close()
  38. return result
  39. if __name__ == '__main__':
  40. obj = MysqlSearchUtils()
  41. reslt = obj.get_all()
  42. for item in reslt:
  43. print(item)
  44. print("-" * 10)
  45. obj.db_close()