functions.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. """
  2. @author: luojunhui
  3. """
  4. import hashlib
  5. from datetime import datetime, timedelta
  6. import requests
  7. def generate_daily_strings(start_date, end_date):
  8. """
  9. Generate daily date_str
  10. :param start_date:
  11. :param end_date:
  12. :return:
  13. """
  14. start = datetime.strptime(start_date, "%Y%m%d")
  15. end = datetime.strptime(end_date, "%Y%m%d")
  16. current = start
  17. date_strings = []
  18. while current <= end:
  19. date_strings.append(current.strftime("%Y%m%d"))
  20. current += timedelta(days=1)
  21. return date_strings
  22. def whisper(video_id):
  23. """
  24. input video_id, output video_text
  25. :param video_id:
  26. :return:
  27. """
  28. url = "http://61.48.133.26:5999/video_to_text"
  29. body = {
  30. "video_id": video_id
  31. }
  32. header = {
  33. "Content-Type": "application/json",
  34. }
  35. response = requests.post(
  36. url=url,
  37. json=body,
  38. headers=header
  39. )
  40. return response.json()
  41. def get_text(video_id):
  42. """
  43. input video_id, output video_text
  44. :param video_id:
  45. :return:
  46. """
  47. url = "http://localhost:8888/get_text"
  48. body = {
  49. "vid": video_id
  50. }
  51. header = {
  52. "Content-Type": "application/json",
  53. }
  54. response = requests.post(
  55. url=url,
  56. json=body,
  57. headers=header
  58. )
  59. return response.json()
  60. def hash_title(title):
  61. """
  62. hash map
  63. :param title:
  64. :return:
  65. """
  66. # 创建md5哈希对象
  67. hash_object = hashlib.md5()
  68. # 对标题进行编码
  69. title_bytes = title.encode('utf-8')
  70. # 更新哈希对象
  71. hash_object.update(title_bytes)
  72. # 获取十六进制形式的哈希值
  73. hash_hex = hash_object.hexdigest()
  74. return hash_hex