Commit d8769c5d by lzzzzl

更新attr_values mongo处理

parent ade8c794
Showing with 9 additions and 18 deletions
# _*_ coding:utf-8 _*_
import json
import traceback
import collections
import pymongo
from urllib import parse
from utils.mysql_handler import MysqlHandler
......@@ -17,7 +16,7 @@ mydb = myclient['ichunt']
mycol = mydb["spu_attrs"]
class PARAM_MONGO(object):
class ParamMongo(object):
def __init__(self):
self.mysql_handler = MysqlHandler('liexin_spu')
......@@ -37,32 +36,24 @@ class PARAM_MONGO(object):
for index in range(0, 10):
data = self.mysql_handler.get_spu(index)
for row in data:
# try:
print(row)
try:
spu_id = row[0]
attr_values = json.loads(row[1])
attr_values = str(json.loads(row[1])).split(",")
new_av_list = list()
for av in attr_values:
attr_name = self.mysql_handler.get_attr_name(av['attr_id'])
attr_value = self.mysql_handler.get_attr_value(av['attr_value_id'])
attr_unit = self.mysql_handler.get_attr_unit(av['attr_unit_id'])
attr_name = self.mysql_handler.get_attr_name(av[0])
attr_value = self.mysql_handler.get_attr_value(av[1])
attr_unit = self.mysql_handler.get_attr_unit(av[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()
except:
traceback.print_exc()
# GOOD CHANCE
if __name__ == '__main__':
param_mongo = PARAM_MONGO()
param_mongo = ParamMongo()
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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment