当前位置:Gxlcms > Python > Python制作数据导入导出工具

Python制作数据导入导出工具

时间:2021-07-01 10:21:17 帮助过:69人阅读

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

以上所述就是本文的全部内容了,希望大家能够喜欢。

人气教程排行