From 3f877ac883449727f498852387f60fd373b487fa Mon Sep 17 00:00:00 2001 From: liaozetao <1107136310@qq.com> Date: Tue, 2 Jan 2024 14:42:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9C=A3=E8=AF=9E=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=B8=85=E6=B4=97=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...act_christmas_2023_cp_rank_user_cp_prop.py | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 python/peko_act_christmas_2023_cp_rank_user_cp_prop.py diff --git a/python/peko_act_christmas_2023_cp_rank_user_cp_prop.py b/python/peko_act_christmas_2023_cp_rank_user_cp_prop.py new file mode 100644 index 000000000..dd451196a --- /dev/null +++ b/python/peko_act_christmas_2023_cp_rank_user_cp_prop.py @@ -0,0 +1,115 @@ +import json + +import redis + + +class RedisUtil: + def __init__(self, host, port, db, password): + self.host = host + self.port = port + self.db = db + self.password = password + + def scan(self, match: str): + keys = [] + res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password) + try: + cursor = 0 + while True: + tup = res.scan(cursor=cursor, match=match, count=1000) + print(tup) + if isinstance(tup[0], int): + cursor = tup[0] + if isinstance(tup[1], list): + keys.extend(tup[1]) + if cursor == 0: + break + except Exception as e: + print('scan is error.', e) + finally: + res.close() + return keys + + def delete(self, name: str): + res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password) + try: + res.delete(name) + except Exception as e: + print('delete ', name, ' is error.', e) + finally: + res.close() + + def hgetall(self, name: str): + data = None + res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password) + try: + data = res.hgetall(name) + except Exception as e: + print('hget ', name, ' is error.', e) + finally: + res.close() + return data + + def hincrby(self, name: str, field, increment): + res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password) + try: + res.hincrby(name, field, increment) + except Exception as e: + print('hincrby ', name, ' is error.', e) + finally: + res.close() + + def hdel(self, name: str, field): + res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password) + try: + res.hdel(name, field) + except Exception as e: + print('hdel ', name, ' is error.', e) + finally: + res.close() + + def hget(self, name: str, field): + data = None + res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password) + try: + data = res.hget(name, field) + except Exception as e: + print('hdel ', name, ' is error.', e) + finally: + res.close() + return data + + def zrange(self, name: str, start: int, end: int, withscores: bool): + data = None + res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password) + try: + data = res.zrange(name, start=start, end=end, withscores=withscores) + except Exception as e: + print('hdel ', name, ' is error.', e) + finally: + res.close() + return data + + +if __name__ == '__main__': + util = RedisUtil(host='172.16.0.2', port=6379, db=0, password='mehpec-vybgig-Demri6') + # util = RedisUtil(host='172.22.0.8', port=6379, db=0, password='pc8DphhaXwTe2jyv') + members = util.hgetall('yinmeng_act_christmas_2023_cp_rank_user_cp_prop') + for member in members: + from_uid = json.loads(member.decode('utf-8'))[1] + data = json.loads(util.hget('yinmeng_act_christmas_2023_cp_rank_user_cp_prop', member).decode('utf-8')) + for k in data: + if k != '@class' and k != 'java.util.HashMap': + to_uid = data[k]['toUid'][1] + cp_task_status = data[k]['cpTaskStatus'] + first = 0 + if '1' in cp_task_status: + first = cp_task_status['1'] + second = 0 + if '2' in cp_task_status: + second = cp_task_status['2'] + third = 0 + if '3' in cp_task_status: + third = cp_task_status['3'] + print(from_uid, ',', to_uid, ',', first, ',', second, ',', third) + break