python制作数据导入导出工具

python 2.6编写,自己瞎写的,备用

”’
export and import elasticsearch data.
simple example at __main__
@author: wgzh159@163.com
@note: uncheck consistency of data, please do it by self
”’
import json
import os
import sys
import time
import urllib2
reload(sys)
sys.setdefaultencoding(‘utf-8’) # @undefinedvariable
class exportesdata():
size = 10000
def __init__(self, url,index,type):
self.url = url+”/”+index+”/”+type+”/_search”
self.index = index
self.type = type
def exportdata(self):
print(“export data begin…”)
begin = time.time()
try:
os.remove(self.index+”_”+self.type+”.json”)
except:
os.mknod(self.index+”_”+self.type+”.json”)
msg = urllib2.urlopen(self.url).read()
print(msg)
obj = json.loads(msg)
num = obj[“hits”][“total”]
start = 0
end = num/self.size+1
while(start

Posted in 未分类