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
a8f1faf6
authored
Nov 10, 2020
by
lzzzzl
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
更新attr_values mongo处理
parent
f7773e9a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
22 deletions
upload/param_mongo.py
upload/param_mongo.py
View file @
a8f1faf6
...
@@ -4,11 +4,13 @@ import traceback
...
@@ -4,11 +4,13 @@ import traceback
import
pymongo
import
pymongo
from
urllib
import
parse
from
urllib
import
parse
from
utils.mysql_handler
import
MysqlHandler
from
utils.mysql_handler
import
MysqlHandler
from
fun.param_thread
import
ParamThread
# 转义用户名和密码
# 转义用户名和密码
user
=
parse
.
quote_plus
(
"ichunt"
)
user
=
parse
.
quote_plus
(
"ichunt"
)
#
pwd = parse.quote_plus("huntmon6699")
pwd
=
parse
.
quote_plus
(
"huntmon6699"
)
pwd
=
parse
.
quote_plus
(
"huntmon66499"
)
#
pwd = parse.quote_plus("huntmon66499")
myclient
=
pymongo
.
MongoClient
(
"mongodb://{0}:{1}@192.168.1.237:27017/?authSource=ichunt&authMechanism=SCRAM-SHA-1"
.
format
(
user
,
pwd
))
myclient
=
pymongo
.
MongoClient
(
"mongodb://{0}:{1}@192.168.1.237:27017/?authSource=ichunt&authMechanism=SCRAM-SHA-1"
.
format
(
user
,
pwd
))
# myclient = pymongo.MongoClient("mongodb://{0}:{1}@172.18.137.23:27017/?authSource=ichunt&authMechanism=SCRAM-SHA-1".format(user, pwd))
# myclient = pymongo.MongoClient("mongodb://{0}:{1}@172.18.137.23:27017/?authSource=ichunt&authMechanism=SCRAM-SHA-1".format(user, pwd))
...
@@ -20,6 +22,15 @@ class ParamMongo(object):
...
@@ -20,6 +22,15 @@ class ParamMongo(object):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
mysql_handler
=
MysqlHandler
(
'liexin_spu'
)
self
.
mysql_handler
=
MysqlHandler
(
'liexin_spu'
)
self
.
data_dict
=
{
0
:
[],
1
:
[],
2
:
[],
3
:
[],
4
:
[],
5
:
[],
6
:
[],
7
:
[],
8
:
[],
9
:
[]}
"""
初始化数据
"""
def
init_data
(
self
):
# 遍历SKU数据
for
i
in
range
(
0
,
10
):
self
.
data_dict
[
i
]
=
self
.
mysql_handler
.
get_spu
(
i
)
def
search_mongo
(
self
,
spu_id
,
data
):
def
search_mongo
(
self
,
spu_id
,
data
):
res
=
mycol
.
find
({
"spu_id"
:
spu_id
})
.
limit
(
1
)
res
=
mycol
.
find
({
"spu_id"
:
spu_id
})
.
limit
(
1
)
...
@@ -32,29 +43,28 @@ class ParamMongo(object):
...
@@ -32,29 +43,28 @@ class ParamMongo(object):
mg_dt
[
'attrs_extend'
]
=
data
mg_dt
[
'attrs_extend'
]
=
data
mycol
.
save
(
mg_dt
)
mycol
.
save
(
mg_dt
)
def
update_mongo
(
self
,
data
):
for
row
in
data
:
try
:
spu_id
=
row
[
0
]
attr_values
=
json
.
loads
(
row
[
1
])
new_av_list
=
list
()
for
vals
in
attr_values
:
val
=
str
(
vals
)
.
split
(
","
)
attr_name
=
self
.
mysql_handler
.
get_attr_name
(
val
[
0
])
attr_value
=
self
.
mysql_handler
.
get_attr_value
(
val
[
1
])
attr_unit
=
self
.
mysql_handler
.
get_attr_unit
(
val
[
2
])
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
)
except
:
traceback
.
print_exc
()
def
run
(
self
):
def
run
(
self
):
for
index
in
range
(
0
,
10
):
self
.
init_data
()
data
=
self
.
mysql_handler
.
get_spu
(
index
)
ParamThread
.
thread_func_ten
(
self
.
update_mongo
,
self
.
data_dict
)
for
row
in
data
:
try
:
spu_id
=
row
[
0
]
attr_values
=
json
.
loads
(
row
[
1
])
new_av_list
=
list
()
for
vals
in
attr_values
:
val
=
str
(
vals
)
.
split
(
","
)
attr_name
=
self
.
mysql_handler
.
get_attr_name
(
val
[
0
])
attr_value
=
self
.
mysql_handler
.
get_attr_value
(
val
[
1
])
attr_unit
=
self
.
mysql_handler
.
get_attr_unit
(
val
[
2
])
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
)
except
:
traceback
.
print_exc
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
param_mongo
=
ParamMongo
()
param_mongo
=
ParamMongo
()
param_mongo
.
run
()
param_mongo
.
run
()
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