Ejemplo n.º 1
0
 def split_code(self):
     #读取数据集dealcode,获取处理验证码图片路径
     deal_image = DealImage()
     all_code_path = self.db.downcode.find({"dealflag": 1, "splitflag": 0}, {"_id": 0, "codepath": 1})
     if all_code_path:
         all_deal_path = []
         all_code_paths = []
         for each_code in all_code_path:
             each_code_path = each_code["codepath"]
             all_code_paths.append(each_code_path)
             #读取数据集dealcode,获取处理图片路径
             each_deal_path = self.db.dealcode.find_one({"codepath": each_code_path}, {"_id": 0, "dealpath": 1})
             if each_deal_path:
                 all_deal_path.append(each_deal_path["dealpath"])
         
         for each_deal_path, each_code_path in zip(all_deal_path, all_code_paths):
             each_deal_path_temp = "../%s" % each_deal_path
             list_split_image_path = deal_image.main_split_image(each_deal_path_temp)
             if len(list_split_image_path):
                 #存入数据集splitcode,验证码路径和分割图片路径
                 exist_result = self.db.splitcode.find_one({"codepath": each_code_path})
                 if not exist_result:
                     self.db.splitcode.insert({"codepath": each_code_path, "splitpath": list_split_image_path, "time": time.ctime()})
                     #更新数据集downcode,分割标志为1
                     self.db.downcode.update({"codepath": each_code_path}, {"$set": {"splitflag": 1}})
                 else:
                     self.db.downcode.update({"codepath": each_code_path}, {"$set": {"splitflag": 0}})