Commit 97d857df by 岳巧源

add ext attr

parent 1523ed6f
{
"jingdong_vc_item_extProps_find_responce": {
"code": "0",
"request_id": "161822.39587.17285233577478939",
"jos_result_dto": {
"result": [
{
"attr_alias": "",
"ext_prop_value": [
{
"value_id": 1335733,
"value_name": "通信",
"sort": 923,
"type": 4,
"att_id": 241394,
"brand_prx": "",
"yn": 1
},
{
"value_id": 1335808,
"value_name": "医疗",
"sort": 925,
"type": 4,
"att_id": 241394,
"brand_prx": "",
"yn": 1
},
{
"value_id": 1335697,
"value_name": "其它",
"sort": 921,
"type": 4,
"att_id": 241394,
"brand_prx": "",
"yn": 1
},
{
"value_id": 1335618,
"value_name": "航空",
"sort": 919,
"type": 4,
"att_id": 241394,
"brand_prx": "",
"yn": 1
},
{
"value_id": 1335647,
"value_name": "工业",
"sort": 918,
"type": 4,
"att_id": 241394,
"brand_prx": "",
"yn": 1
},
{
"value_id": 1335711,
"value_name": "汽车",
"sort": 922,
"type": 4,
"att_id": 241394,
"brand_prx": "",
"yn": 1
},
{
"value_id": 1335674,
"value_name": "航天",
"sort": 920,
"type": 4,
"att_id": 241394,
"brand_prx": "",
"yn": 1
},
{
"value_id": 1335787,
"value_name": "消费",
"sort": 924,
"type": 4,
"att_id": 241394,
"brand_prx": "",
"yn": 1
}
],
"maintain_remark": "",
"type": 4,
"att_id": 235914,
"yn": 1,
"input_type": 2,
"is_required": 1,
"order_sort": 918,
"level": 0,
"inputAreaLevel": "3",
"name": "行业应用",
"val_unit": "",
"cid": 33811
}
],
"return_code": "100",
"is_success": true,
"count": 1,
"return_message": "执行成功"
}
}
}
\ No newline at end of file
......@@ -47,14 +47,14 @@ def update_jd_attr_by_class(conf: dict):
app_key = "CA52430E90209F51D8F5D7B615DDE9AD"
app_secret = "c92691b2379c48de87e699c4c2f7fb32"
for i in range(len(class_ids)):
if i != 0:
break
class_id = class_ids[i]
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)
# 处理京东返回的数据 并尝试修改db
if "result" not in ans["jingdong_vc_item_props_find_responce"]["jos_result_dto"]:
continue
jd_results = ans["jingdong_vc_item_props_find_responce"]["jos_result_dto"]["result"]
for j in range(len(jd_results)):
result = jd_results[j]
......@@ -143,6 +143,70 @@ def update_ext_attr_by_class_ids(conf: dict):
class_ids = []
for i in range(len(results)):
class_ids.append(results[i][0])
# 请求京东平台 获取分类下的 “拓展属性”(vc接口)
method_name = "jingdong.vc.item.extProps.find"
token = "845ce8478b074103b9e78a769d5fa4831y2u"
app_key = "CA52430E90209F51D8F5D7B615DDE9AD"
app_secret = "c92691b2379c48de87e699c4c2f7fb32"
for i in range(len(class_ids)):
class_id = class_ids[i]
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"]
if flag != 1:
continue
attr_id = result["att_id"]
attr_name = result["name"]
unit = result["val_unit"]
is_required = 1
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
else:
print("暂时未兼容此种类型的拓展属性 input_type: " + str(input_type))
# 检查此分类的此拓展属性在 db 中是否已存在,未存在则 insert, 存在则 update
check_sql = "select id from lie_shop_attr where class_id = %s and attr_id = %s"
cursor.execute(query=check_sql, args=(class_id, attr_id,))
db_result = cursor.fetchall()
if len(db_result) == 0:
# 不存在时
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))
else:
update_sql = ""
......
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