_utils.py 3.1 KB

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