demo.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/4/19
  4. import time
  5. from datetime import date, timedelta
  6. # import ast
  7. # task_str = "[('task_id','11')," \
  8. # "('task_name','小年糕小时榜')," \
  9. # "('source','xiaoniangao')," \
  10. # "('start_time','1681834560000')," \
  11. # "('interval','1'),('mode','hour')," \
  12. # "('rule','[{'duration':{'min':40,'max':0}},{'playCnt':{'min':4000,'max':0}},{'period':{'min':10,'max':0}},{'fans':{'min':0,'max':0}},{'videos':{'min':0,'max':0}},{'like':{'min':0,'max':0}},{'videoWidth':{'min':0,'max':0}},{'videoHeight':{'min':0,'max':0}}]')," \
  13. # "('spider_name','')," \
  14. # "('machine','')," \
  15. # "('status','0')," \
  16. # "('create_time','1681889875288')," \
  17. # "('update_time','1681889904908')," \
  18. # "('operator','王坤')]"
  19. # task_str = task_str.replace("'[{", '[{').replace("}}]'", '}}]')
  20. # print(task_str)
  21. # task_list = eval(task_str)
  22. # print(task_list)
  23. # print(type(task_list))
  24. # task_dict = dict(task_list)
  25. # print(task_dict)
  26. # print(type(task_dict))
  27. #
  28. #
  29. # rule = task_dict['rule']
  30. # print(type(rule))
  31. # print(rule)
  32. # print(task_dict)
  33. # task_dict['rule'] = dict()
  34. # for item in rule:
  35. # for k, val in item.items():
  36. # task_dict['rule'][k] = val
  37. # print('\n')
  38. # print(task_dict['rule'])
  39. # print('\n')
  40. # print(task_dict)
  41. # str1 = task_str.split(",('rule',")[0]+"]"
  42. # print(type(str1))
  43. # print(str1)
  44. # eval1 = eval(str1)
  45. # print(type(eval1), eval1)
  46. # dict1 = dict(eval1)
  47. # print(type(dict1), dict1)
  48. # print("============\n")
  49. #
  50. # "[{'duration':{'min':40,'max':0}},{'playCnt':{'min':4000,'max':0}},{'period':{'min':10,'max':0}},{'fans':{'min':0,'max':0}},{'videos':{'min':0,'max':0}},{'like':{'min':0,'max':0}},{'videoWidth':{'min':0,'max':0}},{'videoHeight':{'min':0,'max':0}}]"
  51. # print(task_str.split(",('rule',")[-1].split(",('spider_name'")[0].replace(")", ""))
  52. # # rule_str = task_str.split(",('rule',")[-1].split(",('spider_name'")[0].replace(")", "").replace("'[{", '[{').replace("}}]'", '}}]')
  53. # rule_str = task_str.split(",('rule',")[-1].split(",('spider_name'")[0].replace(")", "")[1:-1]
  54. # print(type(rule_str))
  55. # print(rule_str)
  56. #
  57. #
  58. # rule_list = eval(rule_str)
  59. # print(type(rule_list))
  60. # print(rule_list)
  61. # rule_dict = {'duration': {'min': 40, 'max': 0}, 'playCnt': {'min': 4000, 'max': 0}, 'period': {'min': 10, 'max': 0}, 'fans': {'min': 0, 'max': 0}, 'videos': {'min': 0, 'max': 0}, 'like': {'min': 0, 'max': 0}, 'videoWidth': {'min': 0, 'max': 0}, 'videoHeight': {'min': 0, 'max': 0}}
  62. # rule_dict = {}
  63. #
  64. # for k, v in rule_dict.items():
  65. # print(f"{k}:{v}")
  66. #
  67. # rule_duration_min = rule_dict.get('duration', {}).get('min', 0)
  68. # rule_duration_max = rule_dict.get('duration', {}).get('max', 100000000)
  69. # rule_playCnt_min = rule_dict.get('playCnt', {}).get('min', 0)
  70. # rule_playCnt_max = rule_dict.get('playCnt', {}).get('max', 100000000)
  71. # rule_period_min = rule_dict.get('period', {}).get('min', 0)
  72. # rule_period_max = rule_dict.get('period', {}).get('max', 100000000)
  73. # rule_fans_min = rule_dict.get('fans', {}).get('min', 0)
  74. # rule_fans_max = rule_dict.get('fans', {}).get('max', 100000000)
  75. # rule_videos_min = rule_dict.get('videos', {}).get('min', 0)
  76. # rule_videos_max = rule_dict.get('videos', {}).get('max', 100000000)
  77. # rule_like_min = rule_dict.get('like', {}).get('min', 0)
  78. # rule_like_max = rule_dict.get('like', {}).get('max', 100000000)
  79. # rule_videoWidth_min = rule_dict.get('videoWidth', {}).get('min', 0)
  80. # rule_videoWidth_max = rule_dict.get('videoWidth', {}).get('max', 100000000)
  81. # rule_videoHeight_min = rule_dict.get('videoWidth', {}).get('min', 0)
  82. # rule_videoHeight_max = rule_dict.get('videoWidth', {}).get('max', 100000000)
  83. #
  84. # print(f"rule_duration_min:{rule_duration_min}")
  85. # print(f"rule_duration_max:{rule_duration_max}")
  86. # print(f"rule_playCnt_min:{rule_playCnt_min}")
  87. # print(f"rule_playCnt_max:{rule_playCnt_max}")
  88. # print(f"rule_period_min:{rule_period_min}")
  89. # print(f"rule_period_max:{rule_period_max}")
  90. # print(f"rule_fans_min:{rule_fans_min}")
  91. # print(f"rule_fans_max:{rule_fans_max}")
  92. # print(f"rule_videos_min:{rule_videos_min}")
  93. # print(f"rule_videos_max:{rule_videos_max}")
  94. # print(f"rule_videoWidth_min:{rule_videoWidth_min}")
  95. # print(f"rule_videoWidth_max:{rule_videoWidth_max}")
  96. # print(f"rule_videoHeight_min:{rule_videoHeight_min}")
  97. # print(f"rule_videoHeight_max:{rule_videoHeight_max}")
  98. time_str = (date.today() + timedelta(days=-10)).strftime("%Y-%m-%d %H:%M:%S")
  99. time_stamp = int(time.mktime(time.strptime(time_str, "%Y-%m-%d %H:%M:%S")))
  100. print(time_str)
  101. print(time_stamp)