Commit 0be98dd6 by 岳巧源

add attr

parent df2ecaaa
Showing with 54 additions and 2 deletions
......@@ -184,9 +184,61 @@ def insert_pop_attr_to_db():
print(insert_sql % (class_id, attr_id, attr_name, unit, enum_value, input_type, is_required, status, platform, create_time))
# 单独处理
def handle_pop_unit():
select_sql = "select id, attr_name from lie_shop_attr where platform = 3 and input_type != 10"
config = config_dev
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)):
id = db_result[i][0]
attr_name = db_result[i][1]
unit = process_unit_str(attr_name)
if unit == "":
continue
default_unit = unit
update_sql = "update lie_shop_attr set unit = %s, default_unit = %s where id = %s"
cursor.execute(query=update_sql, args=(unit, default_unit, id,))
db.commit()
print(update_sql % (unit, default_unit, id))
print("==========================>")
select_sql = "select id, unit from lie_shop_attr where platform = 3 and input_type = 10"
cursor.execute(query=select_sql)
db_result = cursor.fetchall()
for i in range(len(db_result)):
id = db_result[i][0]
unit = db_result[i][1]
unit_arr = str(unit).split(",")
length = len(unit_arr[0])
default_unit = unit_arr[0][2:length-1]
update_sql = "update lie_shop_attr set default_unit = %s where id = %s"
cursor.execute(query=update_sql, args=(default_unit, id,))
db.commit()
print(update_sql % (default_unit, id))
def process_unit_str(attr_name: str) -> str:
start = attr_name.find("(")
end = attr_name.rfind(")")
if start == -1 or end == -1 or start >= end or start == 0:
print(attr_name + " can't match")
return ""
else:
name_str = attr_name[:start]
unit_str = attr_name[start+1:end]
if name_str == "" or unit_str == "":
print(attr_name + " can't match")
return ""
print(attr_name + " : " + unit_str)
return unit_str
if __name__ == '__main__':
pass
\ No newline at end of file
handle_pop_unit()
\ 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