Commit 88f0b279 by 岳巧源

add crontab pop.py

parent 16d1fced
Showing with 62 additions and 0 deletions
......@@ -220,6 +220,62 @@ def update_pop_attr(conf: dict):
db.commit()
print(delete_sql % id)
def handle_vc_unit(conf: dict):
"""
用于处理默认单位字段。
default_unit
"""
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, unit, input_type from lie_shop_attr where platform = 3 and unit != ''"
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]
input_type = db_result[i][2]
if input_type != 10:
update_sql = "update lie_shop_attr set default_unit = %s where id = %s"
cursor.execute(query=update_sql, args=(unit, id,))
db.commit()
print(update_sql % (unit, id))
else:
"""
input_type 为10的单位单独处理。
"""
end = str(unit).find(",")
default_unit = unit[2:end-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 handle_default_unit(conf: dict):
"""
保持unit与default_unit一致。
"""
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, unit from lie_shop_attr where platform = 3 and unit = '' and default_unit != ''"
cursor.execute(query=select_sql)
db_result = cursor.fetchall()
for i in range(len(db_result)):
id = db_result[i][0]
update_sql = "update lie_shop_attr set default_unit = '' where id = %s"
cursor.execute(query=update_sql, args=(id,))
db.commit()
print(update_sql % (id))
if __name__ == '__main__':
option = {"dev", "prod"}
......@@ -235,3 +291,9 @@ if __name__ == '__main__':
config = config_prod
update_pop_class(config)
print("======================> pop分类已更新")
update_pop_attr(config)
print("======================> pop参数已更新")
handle_vc_unit(config)
handle_default_unit(config)
print("======================> pop单位处理完毕")
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