Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lzzzzl
/
param_data
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
471629f8
authored
Nov 10, 2020
by
lzzzzl
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
更新attr_values mongo处理
parent
a5a9057d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
fun/param_data.py
upload/param_mongo.py
fun/param_data.py
View file @
471629f8
...
...
@@ -236,3 +236,12 @@ class ParamData(object):
def
get_attr_unit
(
attr_unit_id
,
class_conn
):
sql
=
"SELECT attr_unit_name FROM lie_class_attr_unit WHERE attr_unit_id=
%
s"
%
attr_unit_id
return
DBHandler
.
read
(
class_conn
,
sql
)
"""
获取SPU 数据
"""
@staticmethod
def
get_spu
(
index
,
spu_conn
):
sql
=
"SELECT spu_id,attr_values FROM lie_spu_
%
d WHERE class_id1 != 0 AND class_id2 != 0
\
AND attr_values != '' ORDER BY spu_id LIMIT 100 "
%
index
return
DBHandler
.
read
(
spu_conn
,
sql
)
upload/param_mongo.py
View file @
471629f8
...
...
@@ -5,6 +5,7 @@ import pymongo
from
urllib
import
parse
from
fun.param_thread
import
ParamThread
from
fun.param_data
import
ParamData
from
param_task.task
import
Task
# 转义用户名和密码
...
...
@@ -18,9 +19,11 @@ mydb = myclient['ichunt']
mycol
=
mydb
[
"spu_attrs"
]
class
ParamMongo
(
object
):
class
ParamMongo
(
Task
):
def
__init__
(
self
):
super
()
.
__init__
()
self
.
spu_conn
=
self
.
DBConn
.
db_spu
()
self
.
param_data
=
ParamData
self
.
data_dict
=
{
0
:
[],
1
:
[],
2
:
[],
3
:
[],
4
:
[],
5
:
[],
6
:
[],
7
:
[],
8
:
[],
9
:
[]}
...
...
@@ -30,7 +33,7 @@ class ParamMongo(object):
def
init_data
(
self
):
# 遍历SKU数据
for
i
in
range
(
0
,
10
):
self
.
data_dict
[
i
]
=
self
.
mysql_handler
.
get_spu
(
i
)
self
.
data_dict
[
i
]
=
self
.
param_data
.
get_spu
(
i
,
self
.
spu_conn
)
def
search_mongo
(
self
,
spu_id
,
data
):
res
=
mycol
.
find
({
"spu_id"
:
spu_id
})
.
limit
(
1
)
...
...
@@ -44,6 +47,7 @@ class ParamMongo(object):
mycol
.
save
(
mg_dt
)
def
update_mongo
(
self
,
data
):
class_db
=
self
.
DBConn
.
db_class
()
for
row
in
data
:
try
:
spu_id
=
row
[
0
]
...
...
@@ -51,9 +55,9 @@ class ParamMongo(object):
new_av_list
=
list
()
for
vals
in
attr_values
:
val
=
str
(
vals
)
.
split
(
","
)
attr_name
=
self
.
param_data
.
get_attr_name
(
val
[
0
])
attr_value
=
self
.
param_data
.
get_attr_value
(
val
[
1
])
attr_unit
=
self
.
param_data
.
get_attr_unit
(
val
[
2
])
attr_name
=
self
.
param_data
.
get_attr_name
(
val
[
0
]
,
class_db
)
attr_value
=
self
.
param_data
.
get_attr_value
(
val
[
1
]
,
class_db
)
attr_unit
=
self
.
param_data
.
get_attr_unit
(
val
[
2
]
,
class_db
)
if
attr_name
and
attr_value
and
attr_unit
:
new_av_list
.
append
({
'attr_name'
:
attr_name
,
'attr_value'
:
attr_value
,
'attr_unit'
:
attr_unit
})
self
.
search_mongo
(
spu_id
,
new_av_list
)
...
...
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