demo.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/5/15
  4. import random
  5. from common.scheduling_db import MysqlHelper
  6. class Demo:
  7. @classmethod
  8. def get_user(cls, log_type, crawler, env):
  9. select_user_sql = f"""select * from crawler_user_v3 where task_id=36"""
  10. user_list = MysqlHelper.get_values(log_type, crawler, select_user_sql, env, action="")
  11. print(user_list)
  12. our_uid_list = []
  13. for user in user_list:
  14. our_uid_list.append(user["uid"])
  15. print(our_uid_list)
  16. our_uid = random.choice(our_uid_list)
  17. print(our_uid)
  18. @classmethod
  19. def test_dict(cls):
  20. video_dict = {
  21. "play_cnt": 1000,
  22. "share_cnt": 1000,
  23. "duration": 55,
  24. "video_url": "www.baidu.com"
  25. }
  26. rule_dict = {"play_cnt": {"min": 0, "max": 0},
  27. "fans_cnt": {"min": 0, "max": 0},
  28. "videos_cnt": {"min": 0, "max": 0},
  29. "like_cnt": {"min": 0, "max": 0},
  30. "video_width": {"min": 0, "max": 0},
  31. "video_height": {"min": 0, "max": 0},
  32. "duration": {"min": 0, "max": 0},
  33. "share_cnt": {"min": 0, "max": 0},
  34. "comment_cnt": {"min": 0, "max": 0},
  35. "favorite_cnt": {"min": 0, "max": 0},
  36. "period": {"min": 1, "max": 0}}
  37. # 格式化 rule_dict 最大值取值为 0 的问题
  38. for rule_value in rule_dict.values():
  39. if rule_value["max"] == 0:
  40. rule_value["max"] = 999999999999999
  41. # 格式化 rule_dict 有的 key,video_dict 中没有的问题
  42. for rule_key in rule_dict.keys():
  43. if rule_key not in video_dict.keys():
  44. video_dict[rule_key] = int(rule_dict[rule_key]["max"] / 2)
  45. # 比较结果,输出结果:True / False
  46. for video_key, video_value in video_dict.items():
  47. for rule_key, rule_value in rule_dict.items():
  48. if video_key == rule_key:
  49. result = rule_value["min"] <= video_value <= rule_value["max"]
  50. print(f'{type(video_key)}: {type(rule_value["min"])} <= {type(video_value)} <= {type(rule_value["max"])}')
  51. print(f'{video_key}: {rule_value["min"]} <= {video_value} <= {rule_value["max"]}')
  52. print(f"result:{type(result)}, {result}")
  53. print("=========================\n")
  54. if result is False:
  55. return False
  56. else:
  57. continue
  58. return True
  59. if __name__ == "__main__":
  60. # Demo.get_user("demo", "suisuiniannianyingfuqi", "dev")
  61. print(Demo.test_dict())
  62. # print(500 <= 1000 <= 100000000)
  63. pass