Commit bb96d331 by 岳巧源

add test5

parent 832726b9
Showing with 66 additions and 2 deletions
...@@ -268,5 +268,69 @@ def update_pop_class(): ...@@ -268,5 +268,69 @@ def update_pop_class():
print(sql % (parent_id, class_id, class_name, depth, status, platform, create_time)) print(sql % (parent_id, class_id, class_name, depth, status, platform, create_time))
def update_pop_attr():
config = config_dev
select_sql = "select class_id from lie_shop_class where platform = 3"
db = pymysql.connect(host=config["mysql"]["host"],
port=config["mysql"]["port"],
user=config["mysql"]["user"],
database=config["mysql"]["database"],
password=config["mysql"]["password"])
cursor = db.cursor()
cursor.execute(query=select_sql)
db_result = cursor.fetchall()
for i in range(len(db_result)):
class_id = db_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)
check_sql = "select id from lie_shop_attr where platform = 3 and class_id = %s and attr_id = %s"
cursor.execute(query=check_sql, args=(class_id, attr_id,))
check_result = cursor.fetchall()
if len(check_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))
if __name__ == '__main__': if __name__ == '__main__':
update_pop_class() # update_pop_class()
\ No newline at end of file update_pop_attr()
\ 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