# Path: library/config/database.py

# 
# Path: library/utils/dict.py
# def dot2_(data):
#     
#     '''
#     用于处理字典的key中带有.转化为特定字符，如果写入mongodb，报错
#     :parm:
#         data:需要处理的字典
#     '''
#     
#     new_data = {}
#     if isinstance(data, dict) :
#         for key, vaule in data.items() :
#             key = key.replace('.' , fmt)
#             if isinstance(vaule, dict) :
#                 new_data[key] = dot2_(vaule)
#             else :
#                 new_data[key] = vaule
#     return new_data
# 
# def _2dot(data):   
#      
#     '''
#     用于处理字典的key中带有特定字符转化为.，如果写入mongodb，报错
#     :parm:
#         data:需要处理的字典
#     '''
#     
#     new_data = {}
#     if isinstance(data, dict) :
#         for key, vaule in data.items() :
#             key = key.replace(fmt , '.')
#             if isinstance(vaule, dict) :
#                 new_data[key] = _2dot(vaule)
#             else :
#                 new_data[key] = vaule
#     return new_data


import time, logging, pymongo
from bson.objectid import ObjectId
from library.config.database import mongo_config
from library.utils.dict import dot2_, _2dot
        
        if not (isinstance(insert_list, (list, tuple))):
            self.logger.error(self.log_prefix + ' 批量插入数据失败，原因：参数insert_list不是列表或者元组')
            return (False, '批量插入数据失败，参数insert_list不是列表或者元组')
        
        insert_data = {}
        for insert_dict in insert_list :
            try :
                collect_name = insert_dict['collect']
                # 获取集合
            except :
                continue
                
            try :
                data = insert_dict['data']
                # 获取插入数据
                if not isinstance(data, dict):
                    continue
                    # 插入数据类型不为字典，不执行
                    
                if addtime :
                    data['add_time'] = time.time()
            except :
                continue
        
            if not collect_name in insert_data :
                insert_data[collect_name] = [data] 
            else :
                insert_data[collect_name].append(data)
        

# Path: library/config/database.py

# 
# Path: library/utils/dict.py
# def dot2_(data):
#     
#     '''
#     用于处理字典的key中带有.转化为特定字符，如果写入mongodb，报错
#     :parm:
#         data:需要处理的字典
#     '''
#     
#     new_data = {}
#     if isinstance(data, dict) :
#         for key, vaule in data.items() :
#             key = key.replace('.' , fmt)
#             if isinstance(vaule, dict) :
#                 new_data[key] = dot2_(vaule)
#             else :
#                 new_data[key] = vaule
#     return new_data
# 
# def _2dot(data):   
#      
#     '''
#     用于处理字典的key中带有特定字符转化为.，如果写入mongodb，报错
#     :parm:
#         data:需要处理的字典
#     '''
#     
#     new_data = {}
#     if isinstance(data, dict) :
#         for key, vaule in data.items() :
#             key = key.replace(fmt , '.')
#             if isinstance(vaule, dict) :
#                 new_data[key] = _2dot(vaule)
#             else :
#                 new_data[key] = vaule
#     return new_data


# Path: library/storage/database/mongo.py
import time, logging, pymongo
from bson.objectid import ObjectId
from library.config.database import mongo_config
from library.utils.dict import dot2_, _2dot

        
        if not (isinstance(insert_list, (list, tuple))):
            self.logger.error(self.log_prefix + ' 批量插入数据失败，原因：参数insert_list不是列表或者元组')
            return (False, '批量插入数据失败，参数insert_list不是列表或者元组')
        
        insert_data = {}
        for insert_dict in insert_list :
            try :
                collect_name = insert_dict['collect']
                # 获取集合
            except :
                continue
                
            try :
                data = insert_dict['data']
                # 获取插入数据
                if not isinstance(data, dict):
                    continue
                    # 插入数据类型不为字典，不执行
                    
                if addtime :
                    data['add_time'] = time.time()
            except :
                continue
        
            if not collect_name in insert_data :
                insert_data[collect_name] = [data] 
            else :
                insert_data[collect_name].append(data)
        

        insert_data = dot2_(insert_data)