Commit a48bf509 by 岳巧源

add modify unit

parent 88f0b279
Showing with 33 additions and 0 deletions
...@@ -277,6 +277,39 @@ def handle_default_unit(conf: dict): ...@@ -277,6 +277,39 @@ def handle_default_unit(conf: dict):
print(update_sql % (id)) print(update_sql % (id))
def handle_unit_from_attr_name(conf: dict):
"""
pop的单位很多是从 属性名中提取的。
"""
host = conf["mysql"]["host"]
port = conf["mysql"]["port"]
user = conf["mysql"]["user"]
password = conf["mysql"]["password"]
database = conf["mysql"]["database"]
db = pymysql.connect(host=host, port=port, user=user, password=password, database=database)
cursor = db.cursor()
select_sql = "select id, attr_name from lie_shop_attr where platform = 3 and input_type != 10 and unit = ''"
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]
start = attr_name.find("(")
end = attr_name.find(")")
if start == -1 or end == -1 or start >= end or start == 0:
print(attr_name + " can't match!!")
continue
else:
unit_str = attr_name[start + 1:end]
update_sql = "update lie_shop_attr set unit = %s, default_unit = %s where id = %s"
cursor.execute(query=update_sql, args=(unit_str, unit_str, id,))
db.commit()
print(update_sql % (unit_str, unit_str, id))
if __name__ == '__main__': if __name__ == '__main__':
option = {"dev", "prod"} option = {"dev", "prod"}
if len(sys.argv) >= 2 and sys.argv[1] in option: if len(sys.argv) >= 2 and sys.argv[1] in option:
......
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