ddd.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. """
  2. desc : 素材库数据清洗
  3. 每日运行一次
  4. """
  5. from model.DataBaseUtils import MysqlUtils
  6. db =MysqlUtils()
  7. def title():
  8. sql = """select REPLACE(REPLACE(title, CHAR(10), ''), CHAR(13), '') content,
  9. 1 type,
  10. 0 create_by,
  11. sum(click_count) click_times,
  12. sum(view_count) view_times,
  13. group_concat(distinct book) novels,
  14. max(dt) end_date,min(dt) start_date
  15. from dw_image_cost_day where title!='' and title is not null GROUP BY REPLACE(REPLACE(title, CHAR(10), ''), CHAR(13), '') limit 100
  16. """
  17. df = db.dm.getData_pd(sql)
  18. print(df)
  19. key = ["content", "type"]
  20. tag = ["view_times", "click_times", "novels", "start_date", "end_date", "create_by"]
  21. table = "t_ads_content"
  22. db.zx_test.dfsave2mysql(df, table, key, tag)
  23. def description():
  24. sql = """select REPLACE(REPLACE(description, CHAR(10), ''), CHAR(13), '') content,
  25. 2 type,
  26. 0 create_by,
  27. sum(click_count) click_times,
  28. sum(view_count) view_times,
  29. group_concat(distinct book) novels,
  30. max(dt) end_date,min(dt) start_date
  31. from dw_image_cost_day where description!='' and description is not null GROUP BY REPLACE(REPLACE(description, CHAR(10), ''), CHAR(13), '') limit 100
  32. """
  33. df = db.dm.getData_pd(sql)
  34. print(df)
  35. key = ["content", "type"]
  36. tag = ["view_times", "click_times", "novels", "start_date", "end_date", "create_by"]
  37. table = "t_ads_content"
  38. db.zx_test.dfsave2mysql(df, table, key, tag)
  39. def image():
  40. sql="""select signature,
  41. sum(click_count) click_times,
  42. sum(view_count) view_times,
  43. group_concat(distinct book) novels ,
  44. max(dt) end_date,
  45. min(dt) start_date,
  46. min(preview_url) content,
  47. 1 type,
  48. if(locate(',',signature)>0,0,1) single_img,
  49. 0 create_by
  50. from dw_image_cost_day where dt='2021-05-10' GROUP BY signature"""
  51. df = db.dm.getData_pd(sql)
  52. print(df)
  53. key = ["signature"]
  54. tag = ["view_times", "click_times", "novels", "start_date", "end_date", "create_by", "single_img", "content"]
  55. table = "t_ads_media"
  56. db.zx_test.dfsave2mysql(df, table, key, tag)
  57. def adcreative():
  58. sql="""select signature,title,description,
  59. sum(click_count) click_count,
  60. sum(view_count) view_count,
  61. group_concat(distinct book),
  62. max(dt),min(dt),
  63. min(preview_url)
  64. from dw_image_cost_day where dt='2021-05-10' and signature!='' GROUP BY signature,title,description
  65. """
  66. if __name__ == '__main__':
  67. # title()
  68. # description()
  69. image()