Commit 4fe9350a by 岳巧源

add helper

parent c7df9ed1
Showing with 52 additions and 1 deletions
......@@ -55,6 +55,9 @@ def handle_data(conf: dict):
cursor.execute(query=select_sql)
db_results = cursor.fetchall()
for i in range(len(db_results)):
"""
按照class_id遍历,在redis中找到对应拓展属性
"""
class_id = db_results[i][0]
redis_host = conf["redis"]["host"]
redis_port = conf["redis"]["port"]
......@@ -62,4 +65,51 @@ def handle_data(conf: dict):
redis_db = redis.Redis(host=redis_host, port=redis_port, password=redis_password)
class_id_str = str(class_id)
ans_redis = redis_db.hget("jd_ext_attr", class_id_str)
ans_arr = json.loads(ans_redis)
if ans_redis is None:
"""
一个拓展属性也没有
"""
update_sql = "update lie_shop_attr set is_ext = 1 where platform = 1 and class_id = %s"
cursor.execute(query=update_sql, args=(class_id,))
db.commit()
print(update_sql % (class_id))
continue
ans_arr = json.loads(ans_redis)
ans_set = set(ans_arr)
print(ans_set)
check_ext_sql = "select id, class_id, attr_id from lie_shop_attr where class_id = %s and platform = 1"
cursor.execute(query=check_ext_sql, args=(class_id,))
"""
遍历mysql class_id对应得属性
"""
check_results = cursor.fetchall()
for j in range(len(check_results)):
id = check_results[j][0]
attr_id = check_results[j][2]
if attr_id in ans_set:
"""
找到拓展属性,将is_ext 设为2
"""
update_sql = "update lie_shop_attr set is_ext = 2 where id = %s"
cursor.execute(query=update_sql, args=(id,))
db.commit()
print(update_sql % id)
else:
update_sql = "update lie_shop_attr set is_ext = 1 where id = %s"
cursor.execute(query=update_sql, args=(id,))
db.commit()
print(update_sql % id)
if __name__ == '__main__':
config = config_dev
# handle_data(config)
class_id = 11111111
redis_host = config["redis"]["host"]
redis_port = config["redis"]["port"]
redis_password = config["redis"]["password"]
redis_db = redis.Redis(host=redis_host, port=redis_port, password=redis_password)
class_id_str = str(class_id)
ans_redis = redis_db.hget("jd_ext_attr", class_id_str)
print(ans_redis is None)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment