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
8e37e7a0
authored
Sep 29, 2024
by
岳巧源
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add attr
parent
ccae3bc9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
11 deletions
update_jd_attr.py
update_jd_attr.py
View file @
8e37e7a0
import
json
import
time
import
pymysql
from
common
import
request_to_jd_vc
db
=
pymysql
.
connect
(
host
=
'192.168.1.238'
,
port
=
3306
,
user
=
'liexin_data_distribution'
,
password
=
'liexin_data_distribution#zsyM'
,
database
=
'liexin_data_distribution'
)
cursor
=
db
.
cursor
()
# 主要用于从 lie_shop_class 表中获取到class_id 后,将对应的属性和拓展属性 写入lie_shop_attr表(或者它的copy表)。
def
get_class_ids
():
db
=
pymysql
.
connect
(
host
=
'192.168.1.238'
,
port
=
3306
,
user
=
'liexin_data_distribution'
,
password
=
'liexin_data_distribution#zsyM'
,
database
=
'liexin_data_distribution'
)
query_sql
=
"select distinct class_id from lie_shop_class"
cursor
=
db
.
cursor
()
cursor
.
execute
(
query
=
query_sql
)
results
=
cursor
.
fetchall
()
data
=
[]
for
i
in
range
(
len
(
results
)):
data
.
append
(
results
[
i
][
0
])
cursor
.
close
()
db
.
close
()
return
data
def
update_attr
(
class_id
:
int
):
def
check_class_and_attr
(
class_id
:
int
,
attr_id
:
int
)
->
bool
:
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
,))
results
=
cursor
.
fetchall
()
if
len
(
results
)
!=
0
:
return
True
return
False
def
insert_class_of_attr
(
class_id
:
int
):
"""加入新的分类属性"""
method_name
=
"jingdong.vc.item.props.find"
token
=
"845ce8478b074103b9e78a769d5fa4831y2u"
app_key
=
"CA52430E90209F51D8F5D7B615DDE9AD"
...
...
@@ -30,11 +41,53 @@ def update_attr(class_id: int):
app_secret
=
app_secret
,
param
=
{
"category_leaf_id"
:
class_id
}
)
print
(
json
.
dumps
(
data
,
ensure_ascii
=
False
))
# print(json.dumps(data, ensure_ascii=False))
if
"result"
not
in
data
[
"jingdong_vc_item_props_find_responce"
][
"jos_result_dto"
]:
return
results
=
data
[
"jingdong_vc_item_props_find_responce"
][
"jos_result_dto"
][
"result"
]
for
i
in
range
(
len
(
results
)):
props
=
results
[
i
][
"props"
]
for
j
in
range
(
len
(
props
)):
class_id
=
class_id
attr_id
=
props
[
j
][
"id"
]
attr_name
=
props
[
j
][
"name"
]
unit
=
props
[
j
][
"val_unit"
]
input_type
=
props
[
j
][
"input_type"
]
enum_value
=
"[]"
if
input_type
==
1
or
input_type
==
2
:
# input 为1 或 2 则获取 值id和值名称。
lists
=
[]
for
k
in
range
(
len
(
props
[
j
][
"values"
])):
item
=
dict
()
item
[
"attr_value_id"
]
=
props
[
j
][
"values"
][
k
][
"id"
]
item
[
"attr_value_name"
]
=
props
[
j
][
"values"
][
k
][
"name"
]
lists
.
append
(
item
)
enum_value
=
json
.
dumps
(
lists
,
ensure_ascii
=
False
)
if
input_type
==
10
:
# input_type 为10 则获取单位
lists
=
[]
for
k
in
range
(
len
(
props
[
j
][
"values"
])):
if
"units"
in
props
[
j
][
"values"
][
k
]:
for
x
in
range
(
len
(
props
[
j
][
"values"
][
k
][
"units"
])):
lists
.
append
(
props
[
j
][
"values"
][
k
][
"units"
][
x
])
unit
=
json
.
dumps
(
lists
,
ensure_ascii
=
False
)
if
props
[
j
][
"required"
]
==
True
:
is_required
=
1
else
:
is_required
=
0
status
=
1
platform
=
1
create_time
=
int
(
time
.
time
())
exists
=
check_class_and_attr
(
class_id
,
attr_id
)
if
not
exists
:
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(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
))
def
update_ext_attr
(
class_id
:
int
):
def
insert_class_of_ext_attr
(
class_id
:
int
):
"""加入新的分类拓展属性(拓展属性)"""
method_name
=
"jingdong.vc.item.extProps.find"
token
=
"845ce8478b074103b9e78a769d5fa4831y2u"
app_key
=
"CA52430E90209F51D8F5D7B615DDE9AD"
...
...
@@ -51,4 +104,7 @@ def update_ext_attr(class_id: int):
if
__name__
==
'__main__'
:
update_attr
(
33529
)
\ No newline at end of file
class_ids
=
get_class_ids
()
for
i
in
range
(
len
(
class_ids
)):
class_id
=
class_ids
[
i
]
insert_class_of_attr
(
class_id
)
\ No newline at end of file
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