_utils.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import json
  2. from typing import List, Dict
  3. from datetime import datetime, timedelta
  4. from odps.types import Record
  5. from app.infra.shared.tools import fetch_from_odps
  6. from app.infra.internal.piaoquan import fetch_piaoquan_video_list_detail
  7. class VideoDecodeUtils:
  8. # 获取检测的账号 list
  9. @staticmethod
  10. def get_top_head_videos(execute_dt):
  11. uv_threshold = 500
  12. # dt = (datetime.today() - timedelta(days=1)).strftime("%Y%m%d")
  13. dt = execute_dt
  14. query = f"""
  15. WITH top_video AS
  16. (
  17. SELECT dt, channel, 合作方名,包名,公众号名,hotsencetype, videoid, rootsourceid,title,`merge二级品类`
  18. ,COUNT(DISTINCT mid) AS 访问uv
  19. FROM loghubods.opengid_base_data
  20. WHERE dt = '{dt}'
  21. AND hotsencetype != 1167
  22. AND videoid IS NOT NULL
  23. AND usersharedepth = 0
  24. AND channel IN ('公众号合作-即转-稳定','小程序投流-稳定','服务号合作-Daily-自选','群/企微合作-稳定','公众号买号','服务号买号','公众号投流-稳定','公众号代运营-Daily-系统','公众号合作-Daily-自选','服务号投流','公众号完全代投放','群/企微合作-稳定')
  25. GROUP BY dt
  26. ,channel
  27. ,合作方名
  28. ,包名
  29. ,公众号名
  30. ,hotsencetype
  31. ,videoid
  32. ,rootsourceid
  33. ,title
  34. ,`merge二级品类`
  35. ,推荐状态
  36. HAVING 访问uv >= {uv_threshold}
  37. )
  38. SELECT DISTINCT channel
  39. ,公众号名
  40. ,hotsencetype
  41. ,videoid
  42. ,rootsourceid
  43. ,title
  44. FROM top_video
  45. WHERE 访问uv >= {uv_threshold}
  46. ;
  47. """
  48. result = fetch_from_odps(query)
  49. return result
  50. @staticmethod
  51. def process_odps_data(odps_list: List[Record]):
  52. return [
  53. {
  54. "channel": i.channel,
  55. "account_name": i.公众号名,
  56. "hot_scene_type": i.hotsencetype, # 大数据单词写错。场景: scene
  57. "video_id": i.videoid,
  58. "root_source_id": i.rootsourceid,
  59. "title": i.title,
  60. }
  61. for i in odps_list
  62. ]
  63. @staticmethod
  64. def get_match_video_real_path(raw_match_videos: List, video_id: int):
  65. _response = raw_match_videos[0]["response"]
  66. match_video = json.loads(_response)
  67. for i in match_video:
  68. if i["videoId"] == video_id:
  69. return i["videoOss"]
  70. return None
  71. @staticmethod
  72. async def get_pq_video_real_path(video_id):
  73. response = await fetch_piaoquan_video_list_detail(video_list=[video_id])
  74. video_path = response["data"][0]["ossVideoPath"]
  75. return video_path