Commit a8f1faf6 by lzzzzl

更新attr_values mongo处理

parent f7773e9a
Showing with 18 additions and 8 deletions
......@@ -4,11 +4,13 @@ import traceback
import pymongo
from urllib import parse
from utils.mysql_handler import MysqlHandler
from fun.param_thread import ParamThread
# 转义用户名和密码
user = parse.quote_plus("ichunt")
# pwd = parse.quote_plus("huntmon6699")
pwd = parse.quote_plus("huntmon66499")
pwd = parse.quote_plus("huntmon6699")
# 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}@172.18.137.23:27017/?authSource=ichunt&authMechanism=SCRAM-SHA-1".format(user, pwd))
......@@ -20,6 +22,15 @@ class ParamMongo(object):
def __init__(self):
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):
res = mycol.find({"spu_id": spu_id}).limit(1)
......@@ -32,9 +43,7 @@ class ParamMongo(object):
mg_dt['attrs_extend'] = data
mycol.save(mg_dt)
def run(self):
for index in range(0, 10):
data = self.mysql_handler.get_spu(index)
def update_mongo(self, data):
for row in data:
try:
spu_id = row[0]
......@@ -51,10 +60,11 @@ class ParamMongo(object):
except:
traceback.print_exc()
def run(self):
self.init_data()
ParamThread.thread_func_ten(self.update_mongo, self.data_dict)
if __name__ == '__main__':
param_mongo = ParamMongo()
param_mongo.run()
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