Commit 9be4c064 by 岳巧源

update redis

parent 4fe9350a
Showing with 62 additions and 12 deletions
......@@ -6,6 +6,8 @@ import json
import redis
import pymysql
from common import request_to_jd_vc
config_dev = {
"mysql": {
"host": "192.168.1.238",
......@@ -101,15 +103,63 @@ def handle_data(conf: dict):
print(update_sql % id)
def update_redis(conf: dict):
"""
更新redis中的拓展参数
"""
host = conf["mysql"]["host"]
port = conf["mysql"]["port"]
user = conf["mysql"]["user"]
password = conf["mysql"]["password"]
database = conf["mysql"]["database"]
method_name = "jingdong.vc.item.extProps.find"
token = "845ce8478b074103b9e78a769d5fa4831y2u"
app_key = "CA52430E90209F51D8F5D7B615DDE9AD"
app_secret = "c92691b2379c48de87e699c4c2f7fb32"
select_sql = "select class_id from lie_shop_class where platform = 1"
db = pymysql.connect(host=host, port=port, user=user, password=password, database=database)
cursor = db.cursor()
cursor.execute(query=select_sql)
db_results = cursor.fetchall()
class_attr_mapping = {}
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
"""
redis_host = conf["redis"]["host"]
redis_port = conf["redis"]["port"]
redis_password = conf["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
redis_db.delete("jd_ext_attr")
for i in range(len(db_results)):
class_id = db_results[i][0]
class_attr_mapping[class_id] = []
param = {
"category_leaf_id": class_id,
}
ans = request_to_jd_vc(method_name=method_name, token=token, app_key=app_key, app_secret=app_secret,
param=param)
print("request to jd ....")
if "result" not in ans["jingdong_vc_item_extProps_find_responce"]["jos_result_dto"]:
continue
jd_results = ans["jingdong_vc_item_extProps_find_responce"]["jos_result_dto"]["result"]
for j in range(len(jd_results)):
result = jd_results[j]
attr_id = result["att_id"]
class_attr_mapping[class_id].append(attr_id)
for class_id in class_attr_mapping:
key = str(class_id)
attr_ids = class_attr_mapping[class_id]
if len(attr_ids) == 0:
continue
value = json.dumps(attr_ids, ensure_ascii=False)
redis_db.hset(name="jd_ext_attr", key=key, value=value)
print("jd_ext_attr", key, value)
if __name__ == '__main__':
config = config_prod
update_redis(config)
......@@ -10,7 +10,7 @@ if __name__ == '__main__':
app_key = "CA52430E90209F51D8F5D7B615DDE9AD"
app_secret = "c92691b2379c48de87e699c4c2f7fb32"
param = {
"category_leaf_id": 14122
"category_leaf_id": 14119
}
ans = request_to_jd_vc(method_name=method_name, token=token, app_key=app_key, app_secret=app_secret, param=param)
print(json.dumps(ans, ensure_ascii=False))
......@@ -28,3 +28,4 @@ if __name__ == '__main__':
# .\gf_windows_amd64.exe gen dao -l "mysql:liexin_data_distribution:liexin_data_distribution#zsyM@tcp(192.168.1.238:3306)/liexin_data_distribution" -t "lie_shop_push_sku_log" -r "lie_"
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