Commit 806bac94 by 岳巧源

add attr

parent 108374fa
Showing with 51 additions and 3 deletions
...@@ -97,7 +97,6 @@ def get_pop_attr(class_id: int): ...@@ -97,7 +97,6 @@ def get_pop_attr(class_id: int):
"field": "attrValueList" "field": "attrValueList"
} }
ans = request_to_jd_pop(method_name, token, app_key, app_secret, param) ans = request_to_jd_pop(method_name, token, app_key, app_secret, param)
print(json.dumps(ans, ensure_ascii=False))
return ans return ans
def insert_pop_class_to_db(): def insert_pop_class_to_db():
...@@ -137,9 +136,58 @@ def insert_pop_attr_to_db(): ...@@ -137,9 +136,58 @@ def insert_pop_attr_to_db():
result = cursor.fetchall() result = cursor.fetchall()
for i in range(len(result)): for i in range(len(result)):
class_id = result[i][0] class_id = result[i][0]
ans = get_pop_attr(class_id)
result = ans["jingdong_category_read_findAttrsByCategoryIdUnlimitCate_responce"]["findattrsbycategoryidunlimitcate_result"]
for j in range(len(result)):
input_type = result[j]["inputType"]
attr_id = result[j]["id"]
attr_name = result[j]["name"]
enum_value = ""
flag = result[j]["isRequired"]
status = 1
platform = 3
create_time = int(time.time())
unit = ""
if flag:
is_required = 1
else:
is_required = 0
if input_type == 1 or input_type == 2:
value_list = result[j]["attrValueList"]
tmp_list = []
for k in range(len(value_list)):
attr_value_id = value_list[k]["id"]
attr_value_name = value_list[k]["name"]
item = {
"attr_value_id": attr_value_id,
"attr_value_name": attr_value_name
}
tmp_list.append(item)
enum_value = json.dumps(tmp_list, ensure_ascii=False)
else:
enum_value = "[]"
if input_type == 10:
# 单独处理单位
features = result[j]["features"]
for k in range(len(features)):
item = features[k]
if item["key"] == "combinationValue":
unit_str = item["fvalue"]
unit_arr = json.loads(unit_str)
unit_item = unit_arr[0]
unit_list = unit_item["unit"]
unit = json.dumps(unit_list, ensure_ascii=False)
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))
if __name__ == '__main__': if __name__ == '__main__':
insert_pop_class_to_db() ans = get_pop_attr(33593)
\ No newline at end of file print(json.dumps(ans, ensure_ascii=False))
\ 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