function.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import requests
  6. from config import ACCOUNT_VIDEO, ARTICLE_URL
  7. def get_pq_video_detail(video_id):
  8. """
  9. 获取票圈视频详情信息
  10. :return:
  11. """
  12. url = "https://longvideoapi.piaoquantv.com/longvideoapi/openapi/video/batchSelectVideoInfo"
  13. data = {
  14. "videoIdList": [video_id]
  15. }
  16. header = {
  17. "Content-Type": "application/json",
  18. }
  19. response = requests.post(url, json=data, headers=header)
  20. return response.json()
  21. def generate_response(gh_id):
  22. """
  23. 输入gh_id, 通过配置文件, 返回结果
  24. :param gh_id:
  25. :return:
  26. """
  27. msg_list = ACCOUNT_VIDEO[gh_id]
  28. response_list = []
  29. for msg in msg_list:
  30. item = {
  31. "groupIndex": msg['groupIndex'],
  32. "msgDataList": []
  33. }
  34. video_info_list = sorted(msg['groupVideoList'], key=lambda x: x['videoIndex'])
  35. for video in video_info_list:
  36. video_id = video['videoId']
  37. video_detail = get_pq_video_detail(video_id)['data'][0]
  38. obj = {
  39. "msgType": 1,
  40. "title": video_detail['title'],
  41. "coverUrl": video_detail['shareImgPath'],
  42. "miniAppId": "wxbdd2a2e93d9a6e25",
  43. "miniPagePath": video['pagePath'],
  44. "newsUrl": "",
  45. "newsDescription": "",
  46. "miniVideoId": video_id
  47. }
  48. item['msgDataList'].append(obj)
  49. article_obj = ARTICLE_URL[gh_id]
  50. item['msgDataList'].append(article_obj)
  51. response_list.append(item)
  52. return response_list