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
e0a0941a
authored
Sep 28, 2024
by
larosa
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add tmp handle py file
parent
ca984cee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
140 additions
and
0 deletions
tmp.py
tmp2.py
tmp.py
0 → 100644
View file @
e0a0941a
import
json
import
time
import
pymysql
from
common
import
request_to_jd_vc
def
get_db_connect
(
host
,
port
,
user
,
password
,
database
):
db
=
pymysql
.
connect
(
host
=
host
,
port
=
port
,
user
=
user
,
password
=
password
,
database
=
database
)
cursor
=
db
.
cursor
()
return
db
,
cursor
def
get_attr
():
pass
def
get_ext_attr
():
pass
if
__name__
==
'__main__'
:
# 临时处理 京东参数问题 之后会删除
db
,
cursor
=
get_db_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_attr_copy1"
cursor
.
execute
(
query
=
query_sql
)
results
=
cursor
.
fetchall
()
with
open
(
'config.json'
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
json_data
=
json
.
load
(
f
)
token
=
json_data
[
"shop_vc"
][
"token"
]
app_key
=
json_data
[
"shop_vc"
][
"app_key"
]
app_secret
=
json_data
[
"shop_vc"
][
"app_secret"
]
for
i
in
range
(
len
(
results
)):
class_id
=
results
[
i
][
0
]
ans
=
request_to_jd_vc
(
method_name
=
"jingdong.vc.item.props.find"
,
token
=
token
,
app_key
=
app_key
,
app_secret
=
app_secret
,
param
=
{
"category_leaf_id"
:
class_id
})
# print(json.dumps(ans, ensure_ascii=False))
jd_results
=
ans
[
"jingdong_vc_item_props_find_responce"
][
"jos_result_dto"
][
"result"
]
for
j
in
range
(
len
(
jd_results
)):
props
=
jd_results
[
j
][
"props"
]
for
k
in
range
(
len
(
props
)):
attr_id
=
props
[
k
][
"id"
]
attr_name
=
props
[
k
][
"name"
]
unit
=
props
[
k
][
"val_unit"
]
jd_value
=
props
[
k
][
"values"
]
if
len
(
jd_value
)
==
0
:
enum_value
=
"[]"
else
:
enum_value
=
json
.
dumps
(
jd_value
,
ensure_ascii
=
False
)
input_type
=
props
[
k
][
"input_type"
]
flag
=
props
[
k
][
"required"
]
if
flag
:
is_required
=
1
else
:
is_required
=
0
create_time
=
int
(
time
.
time
())
check_sql
=
"select id from lie_shop_attr_copy1 where class_id =
%
s and attr_id =
%
s"
cursor
.
execute
(
query
=
check_sql
,
args
=
(
class_id
,
attr_id
,))
check_results
=
cursor
.
fetchall
()
if
len
(
check_results
)
!=
0
:
#说明此class_id 下的此属性id是已经存在的
continue
else
:
insert_sql
=
"insert into lie_shop_attr_copy1 (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
,
1
,
1
,
create_time
))
db
.
commit
()
print
(
insert_sql
%
(
class_id
,
attr_id
,
attr_name
,
unit
,
enum_value
,
input_type
,
is_required
,
1
,
1
,
create_time
))
print
(
"=================================================================="
)
tmp2.py
0 → 100644
View file @
e0a0941a
import
json
import
time
import
pymysql
from
common
import
request_to_jd_vc
def
get_db_connect
(
host
,
port
,
user
,
password
,
database
):
db
=
pymysql
.
connect
(
host
=
host
,
port
=
port
,
user
=
user
,
password
=
password
,
database
=
database
)
cursor
=
db
.
cursor
()
return
db
,
cursor
def
get_attr
():
pass
def
get_ext_attr
():
pass
if
__name__
==
'__main__'
:
# 处理拓展参数问题
db
,
cursor
=
get_db_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_attr_copy1"
cursor
.
execute
(
query
=
query_sql
)
results
=
cursor
.
fetchall
()
# results = [[33607]]
with
open
(
'config.json'
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
json_data
=
json
.
load
(
f
)
token
=
json_data
[
"shop_vc"
][
"token"
]
app_key
=
json_data
[
"shop_vc"
][
"app_key"
]
app_secret
=
json_data
[
"shop_vc"
][
"app_secret"
]
for
i
in
range
(
len
(
results
)):
class_id
=
results
[
i
][
0
]
ans
=
request_to_jd_vc
(
method_name
=
"jingdong.vc.item.extProps.find"
,
token
=
token
,
app_key
=
app_key
,
app_secret
=
app_secret
,
param
=
{
"category_leaf_id"
:
class_id
})
# print(json.dumps(ans, ensure_ascii=False))
if
"result"
not
in
ans
[
"jingdong_vc_item_extProps_find_responce"
][
"jos_result_dto"
]:
continue
jd_results
=
ans
[
"jingdong_vc_item_extProps_find_responce"
][
"jos_result_dto"
][
"result"
]
for
j
in
range
(
len
(
jd_results
)):
attr_id
=
jd_results
[
j
][
"att_id"
]
attr_name
=
jd_results
[
j
][
"name"
]
unit
=
jd_results
[
j
][
"val_unit"
]
tmp_value
=
jd_results
[
j
][
"ext_prop_value"
]
vals
=
[]
for
k
in
range
(
len
(
tmp_value
)):
value_id
=
tmp_value
[
k
][
"value_id"
]
value_name
=
tmp_value
[
k
][
"value_name"
]
item
=
{
"attr_value_id"
:
value_id
,
"attr_value_name"
:
value_name
,
}
vals
.
append
(
item
)
enum_value
=
json
.
dumps
(
vals
,
ensure_ascii
=
False
)
input_type
=
jd_results
[
j
][
"input_type"
]
flag
=
jd_results
[
j
][
"is_required"
]
if
flag
==
1
:
is_required
=
1
else
:
is_required
=
0
status
=
1
platform
=
1
create_time
=
int
(
time
.
time
())
check_sql
=
"select id from lie_shop_attr_copy1 where class_id =
%
s and attr_id =
%
s"
cursor
.
execute
(
check_sql
,
args
=
(
class_id
,
attr_id
,))
db_ans
=
cursor
.
fetchall
()
if
len
(
db_ans
)
!=
0
:
continue
insert_sql
=
"insert into lie_shop_attr_copy1 (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))
print
(
insert_sql
%
(
class_id
,
attr_id
,
attr_name
,
unit
,
enum_value
,
input_type
,
is_required
,
status
,
platform
,
create_time
))
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