1 importconfigparser2 importpymongo3 from pymongo importMongoClient4 importtime5
6 print(‘以insertTime为条件查询;可以按通话id筛选数据‘)7 count =08 f = open(‘获取数据.txt‘, ‘w‘,encoding=‘utf-8‘) #在写入文件夹是会报编码格式错误,所以增加encoding=‘utf-8‘解决
9 cf =configparser.ConfigParser()10 #读取当前目录下的配置文件db.conf
11 cf.read(‘db.conf‘)12 get_start_time = cf.getint(‘mongodb‘,‘start_time‘)13 get_end_time = cf.getint(‘mongodb‘,‘end_time‘)14 get_call_id = cf.get(‘mongodb‘,‘call_id‘)15 #将时间戳毫秒转换为秒,db内的时间戳为毫秒单位,python的time为秒单位,所以除以1000
16 s_local_time = time.localtime(get_start_time/1000)17 e_local_time = time.localtime(get_end_time/1000)18 #将秒转换为日期格式2017-01-01 12:00:00
19 s_time = time.strftime(‘%Y-%m-%d %H:%M:%S‘,s_local_time)20 e_time = time.strftime(‘%Y-%m-%d %H:%M:%S‘,e_local_time)21
22 print(‘数据库IP:‘,cf.get(‘mongodb‘,‘db_ip‘),‘\n数据库Port:‘,cf.getint(‘mongodb‘,‘