Commit 16d1fced by 岳巧源

add crontab pop py

parent 40532b61
Showing with 81 additions and 5 deletions
......@@ -97,6 +97,14 @@ def update_pop_attr(conf: dict):
"cid": class_id,
"field": "attrValueList"
}
"""
预先把分类下面的属性查出来
"""
check_sql = "select id, class_id, attr_id, attr_name, unit, enum_value, input_type, is_required from lie_shop_attr where platform = 3 and status = 1 and class_id = %s"
cursor.execute(query=check_sql, args=(class_id,))
check_result = cursor.fetchall()
api_attr_id_set = set()
api_attr_name_set = set()
ans = request_to_jd_pop(method_name, token, app_key, app_secret, param)
result = ans["jingdong_category_read_findAttrsByCategoryIdUnlimitCate_responce"]["findattrsbycategoryidunlimitcate_result"]
for j in range(len(result)):
......@@ -106,8 +114,14 @@ def update_pop_attr(conf: dict):
enum_value = ""
flag = result[j]["isRequired"]
status = 1
"""
将attr_id 和 attr_name加入集合
"""
api_attr_id_set.add(attr_id)
api_attr_name_set.add(attr_name)
platform = 3
create_time = int(time.time())
update_time = int(time.time())
unit = ""
if flag:
is_required = 1
......@@ -138,11 +152,73 @@ def update_pop_attr(conf: dict):
unit_item = unit_arr[0]
unit_list = unit_item["unit"]
unit = json.dumps(unit_list, ensure_ascii=False)
"""
检查属性需不需要更新等等。。。
"""
exists_attr = False
now_attr_map = {
"attr_id": attr_id,
"attr_name": attr_name,
"unit": unit,
"enum_value": enum_value,
"input_type": input_type,
"is_required": is_required,
}
for z in range(len(check_result)):
primary_id = check_result[z][0]
origin_class_id = check_result[z][1]
origin_attr_id = check_result[z][2]
origin_attr_name = check_result[z][3]
origin_unit = check_result[z][4]
origin_enum_value = check_result[z][5]
origin_input_type = check_result[z][6]
origin_is_required = check_result[z][7]
"""
原来数据库中的属性map
"""
origin_attr_map = {
"attr_id": origin_attr_id,
"attr_name": origin_attr_name,
"unit": origin_unit,
"enum_value": origin_enum_value,
"input_type": origin_input_type,
"is_required": origin_is_required,
}
flag1 = (origin_attr_id == attr_id) and (origin_attr_name == attr_name)
flag2 = (origin_attr_id == attr_id) and (origin_attr_name != attr_name)
flag3 = (origin_attr_id != attr_id) and (origin_attr_name == attr_name)
if flag1 or flag2 or flag3:
"""
检查其他项是否需要更新,有一个属性不一样就要执行update
"""
exists_attr = True
for key in origin_attr_map:
if origin_attr_map[key] != now_attr_map[key]:
update_sql1 = "update lie_shop_attr set attr_id = %s, attr_name = %s, unit = %s, enum_value = %s, input_type = %s, is_required = %s, update_time = %s , is_mapping = 0 where id = %s"
cursor.execute(query=update_sql1, args=(attr_id, attr_name, unit, enum_value, input_type, is_required, update_time, primary_id))
db.commit()
print(update_sql1 % (attr_id, attr_name, unit, enum_value, input_type, is_required, update_time, primary_id))
break
break
else:
continue
if not exists_attr:
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))
"""
将api返回中没有的属性设为禁用
"""
for z in range(len(check_result)):
id = check_result[z][0]
origin_attr_id = check_result[z][2]
origin_attr_name = check_result[z][3]
if origin_attr_id not in api_attr_id_set and origin_attr_name not in api_attr_name_set:
delete_sql = "update lie_shop_attr set status = 0 where id = %s"
cursor.execute(query=delete_sql, args=(id,))
db.commit()
print(delete_sql % id)
if __name__ == '__main__':
......
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