Commit b3f0ea27 by 岳巧源

add insert ext attr

parent 171d9ef1
Showing with 62 additions and 0 deletions
...@@ -167,7 +167,69 @@ def insert_vc_attr(conf: dict): ...@@ -167,7 +167,69 @@ def insert_vc_attr(conf: dict):
def insert_vc_ext_attr(conf: dict): def insert_vc_ext_attr(conf: dict):
"""
基于lie_shop_attr中的class_id来更新 “拓展” 属性
"""
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()
for i in range(len(db_results)):
class_id = db_results[i][0]
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)
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]
flag = result["is_required"]
is_required = flag
attr_id = result["att_id"]
attr_name = result["name"]
unit = result["val_unit"]
status = 1
platform = 1
create_time = int(time.time())
input_type = result["input_type"]
enum_value = "[]"
# 根据 input_type 不同类型分别处理
if input_type == 1 or input_type == 2:
# 单选或者多选,获取选项值
ext_prop_value = result["ext_prop_value"]
tmp_list_value = []
for k in range(len(ext_prop_value)):
value = ext_prop_value[k]
attr_value_id = value["value_id"]
attr_value_name = value["value_name"]
item = {
"attr_value_id": attr_value_id,
"attr_value_name": attr_value_name
}
tmp_list_value.append(item)
enum_value = json.dumps(tmp_list_value, ensure_ascii=False)
elif input_type == 3:
# 文本类型,无选项值
pass pass
else:
print("暂时未兼容此种类型的拓展属性 input_type: " + str(input_type))
insert_sql = "insert into lie_shop_attr (class_id, attr_id, attr_name, unit, enum_value, input_type, is_required, status, platform, create_time) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
cursor.execute(query=insert_sql, args=(class_id, attr_id, attr_name, unit, enum_value, input_type, is_required, status, platform, create_time,))
db.commit()
print(insert_sql % (class_id, attr_id, attr_name, unit, enum_value, input_type, is_required, status, platform, create_time))
......
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