Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
岳巧源
/
jd_data_process
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4e542e1f
authored
Oct 10, 2024
by
larosa
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add update attr
parent
be5f8e64
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
1 deletions
tmp.json
update_jd_attr.py
tmp.json
View file @
4e542e1f
This diff is collapsed.
Click to expand it.
update_jd_attr.py
View file @
4e542e1f
...
...
@@ -2,6 +2,8 @@
# 分类数据来源于lie_shop_class 数据库中class_id 字段或 parent_id 字段
import
json
import
sys
import
time
import
pymysql
from
common
import
request_to_jd_vc
...
...
@@ -68,9 +70,58 @@ def update_jd_attr_by_class(conf: dict):
check_sql
=
"select id from lie_shop_attr where class_id =
%
s and attr_id =
%
s"
cursor
.
execute
(
query
=
check_sql
,
args
=
(
class_id
,
attr_id
))
db_result
=
cursor
.
fetchall
()
attr_name
=
prop
[
"name"
]
unit
=
prop
[
"val_unit"
]
input_type
=
prop
[
"input_type"
]
platform
=
1
status
=
1
is_required
=
1
enum_value
=
"[]"
if
input_type
==
1
or
input_type
==
2
:
# 单选或者多选 把选项取出来
tmp_value_list
=
[]
values
=
prop
[
"values"
]
for
index
in
range
(
len
(
values
)):
attr_value_id
=
values
[
index
][
"id"
]
attr_value_name
=
values
[
index
][
"name"
]
item_map
=
{
"attr_value_id"
:
attr_value_id
,
"attr_value_name"
:
attr_value_name
,
}
tmp_value_list
.
append
(
item_map
)
enum_value
=
json
.
dumps
(
tmp_value_list
,
ensure_ascii
=
False
)
elif
input_type
==
3
:
# 文本类型
# 文本类型没有可选值
pass
elif
input_type
==
7
:
# 数值类型
# 数值类型没有可选值
pass
elif
input_type
==
10
:
# 多单位多解析的方式
# 多单位多解析 需要特殊处理单位字段
tmp_unit_list
=
[]
values
=
prop
[
"values"
]
for
index
in
range
(
len
(
values
)):
if
"units"
in
values
[
index
]:
unit_list
=
values
[
index
][
"units"
]
for
x
in
range
(
len
(
unit_list
)):
tmp_unit_list
.
append
(
unit_list
[
x
])
unit
=
json
.
dumps
(
tmp_unit_list
,
ensure_ascii
=
False
)
else
:
print
(
"此input_type类型暂未兼容处理!请单独处理!"
)
create_time
=
int
(
time
.
time
())
# 如果db中暂时没有这条数据 就插入
if
len
(
db_result
)
==
0
:
pass
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
))
# 把sql语句输出到一个文件中
else
:
# TODO 已经存在,考虑更新, 鉴于更新的情况复杂,稍后处理
pass
...
...
@@ -80,6 +131,7 @@ def update_jd_attr_by_class(conf: dict):
if
__name__
==
'__main__'
:
option
=
{
"dev"
,
"prod"
}
if
len
(
sys
.
argv
)
>=
2
and
sys
.
argv
[
1
]
in
option
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment