dw_ad_day.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import logging
  2. from model.DataBaseUtils import MysqlUtils,CkUtils
  3. from model.DateUtils import DateUtils
  4. logging.getLogger().setLevel(logging.WARNING)
  5. import pandas as pd
  6. db = MysqlUtils()
  7. ck = CkUtils()
  8. du=DateUtils()
  9. def run(dt):
  10. sql=f"""SELECT a.dt,a.ad_id,b.ad_name,b.type,'',a.cost,view_count,click_count,follow_count,order_count,order_amount,
  11. title,description,e.channel,pitcher,book,platform,stage,ifnull(image_id,'')
  12. from
  13. ad_cost_day a
  14. left join ad_info b on a.ad_id=b.ad_id
  15. left join adcreative_info c on b.adcreative_id=c.adcreative_id
  16. left join channel_by_account_daily e on b.account_id=e.account_id and a.dt=e.dt
  17. left join channel_info_daily f on e.channel=f.channel and e.dt=f.dt
  18. where a.dt='{dt}' """
  19. data = db.quchen_text.get_data_list(sql)
  20. # print(data)
  21. # 图片链接拼接
  22. li = []
  23. for i in data:
  24. # print(i)
  25. li.extend(i[-1].split(','))
  26. # print(li)
  27. sql3 = f"select image_id,preview_url from image_info where image_id in ({str(set(li))[1:-1]})"
  28. image_di = {}
  29. image_data = db.quchen_text.getData(sql3)
  30. for x in image_data:
  31. image_di[x[0]] = x[1]
  32. # print(image_di)
  33. for i in data:
  34. y = ''
  35. for j in i[-1].split(','):
  36. if image_di.get(j):
  37. y = y + ',' + image_di.get(j)
  38. i.append(y[1:])
  39. # print(data)
  40. db.dm.executeMany("replace into dw_ad_day values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",data)
  41. def day():
  42. run(du.getNow())
  43. if __name__ == '__main__':
  44. day()