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
d8769c5d
authored
Nov 10, 2020
by
lzzzzl
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
更新attr_values mongo处理
parent
ade8c794
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
18 deletions
upload/param_mongo.py
upload/param_mongo.py
View file @
d8769c5d
# _*_ coding:utf-8 _*_
# _*_ coding:utf-8 _*_
import
json
import
json
import
traceback
import
traceback
import
collections
import
pymongo
import
pymongo
from
urllib
import
parse
from
urllib
import
parse
from
utils.mysql_handler
import
MysqlHandler
from
utils.mysql_handler
import
MysqlHandler
...
@@ -17,7 +16,7 @@ mydb = myclient['ichunt']
...
@@ -17,7 +16,7 @@ mydb = myclient['ichunt']
mycol
=
mydb
[
"spu_attrs"
]
mycol
=
mydb
[
"spu_attrs"
]
class
P
ARAM_MONGO
(
object
):
class
P
aramMongo
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
mysql_handler
=
MysqlHandler
(
'liexin_spu'
)
self
.
mysql_handler
=
MysqlHandler
(
'liexin_spu'
)
...
@@ -37,32 +36,24 @@ class PARAM_MONGO(object):
...
@@ -37,32 +36,24 @@ class PARAM_MONGO(object):
for
index
in
range
(
0
,
10
):
for
index
in
range
(
0
,
10
):
data
=
self
.
mysql_handler
.
get_spu
(
index
)
data
=
self
.
mysql_handler
.
get_spu
(
index
)
for
row
in
data
:
for
row
in
data
:
# try:
try
:
print
(
row
)
spu_id
=
row
[
0
]
spu_id
=
row
[
0
]
attr_values
=
json
.
loads
(
row
[
1
]
)
attr_values
=
str
(
json
.
loads
(
row
[
1
]))
.
split
(
","
)
new_av_list
=
list
()
new_av_list
=
list
()
for
av
in
attr_values
:
for
av
in
attr_values
:
attr_name
=
self
.
mysql_handler
.
get_attr_name
(
av
[
'attr_id'
])
attr_name
=
self
.
mysql_handler
.
get_attr_name
(
av
[
0
])
attr_value
=
self
.
mysql_handler
.
get_attr_value
(
av
[
'attr_value_id'
])
attr_value
=
self
.
mysql_handler
.
get_attr_value
(
av
[
1
])
attr_unit
=
self
.
mysql_handler
.
get_attr_unit
(
av
[
'attr_unit_id'
])
attr_unit
=
self
.
mysql_handler
.
get_attr_unit
(
av
[
2
])
if
attr_name
and
attr_value
and
attr_unit
:
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
})
new_av_list
.
append
({
'attr_name'
:
attr_name
,
'attr_value'
:
attr_value
,
'attr_unit'
:
attr_unit
})
self
.
search_mongo
(
spu_id
,
new_av_list
)
self
.
search_mongo
(
spu_id
,
new_av_list
)
#
except:
except
:
#
traceback.print_exc()
traceback
.
print_exc
()
# GOOD CHANCE
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
param_mongo
=
P
ARAM_MONGO
()
param_mongo
=
P
aramMongo
()
param_mongo
.
run
()
param_mongo
.
run
()
# for x in mycol.find({"spu_id": 123456}):
# print(x)
# x['attrs_extends'] = [{"attr_name": "电压","attr_value": "1000","attr_unit": "V"},
# {"attr_name": "电流","attr_value": "50","attr_unit": "A"}]
# mycol.save(x)
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