# -*- coding: utf-8 -*- # @Author: wangkun # @Time: 2023/5/15 import random from common.scheduling_db import MysqlHelper class Demo: @classmethod def get_user(cls, log_type, crawler, env): select_user_sql = f"""select * from crawler_user_v3 where task_id=36""" user_list = MysqlHelper.get_values(log_type, crawler, select_user_sql, env, action="") print(user_list) our_uid_list = [] for user in user_list: our_uid_list.append(user["uid"]) print(our_uid_list) our_uid = random.choice(our_uid_list) print(our_uid) @classmethod def test_dict(cls): video_dict = { "play_cnt": 1000, "share_cnt": 1000, "duration": 55, "video_url": "www.baidu.com" } rule_dict = {"play_cnt": {"min": 0, "max": 0}, "fans_cnt": {"min": 0, "max": 0}, "videos_cnt": {"min": 0, "max": 0}, "like_cnt": {"min": 0, "max": 0}, "video_width": {"min": 0, "max": 0}, "video_height": {"min": 0, "max": 0}, "duration": {"min": 0, "max": 0}, "share_cnt": {"min": 0, "max": 0}, "comment_cnt": {"min": 0, "max": 0}, "favorite_cnt": {"min": 0, "max": 0}, "period": {"min": 1, "max": 0}} # 格式化 rule_dict 最大值取值为 0 的问题 for rule_value in rule_dict.values(): if rule_value["max"] == 0: rule_value["max"] = 999999999999999 # 格式化 rule_dict 有的 key,video_dict 中没有的问题 for rule_key in rule_dict.keys(): if rule_key not in video_dict.keys(): video_dict[rule_key] = int(rule_dict[rule_key]["max"] / 2) # 比较结果,输出结果:True / False for video_key, video_value in video_dict.items(): for rule_key, rule_value in rule_dict.items(): if video_key == rule_key: result = rule_value["min"] <= video_value <= rule_value["max"] print(f'{type(video_key)}: {type(rule_value["min"])} <= {type(video_value)} <= {type(rule_value["max"])}') print(f'{video_key}: {rule_value["min"]} <= {video_value} <= {rule_value["max"]}') print(f"result:{type(result)}, {result}") print("=========================\n") if result is False: return False else: continue return True if __name__ == "__main__": # Demo.get_user("demo", "suisuiniannianyingfuqi", "dev") print(Demo.test_dict()) # print(500 <= 1000 <= 100000000) pass