gn_dataset
This commit is contained in:
@@ -420,6 +420,43 @@ class ElasticHelper():
|
||||
print(self.es.cat.count(index=index_name, format="json"))
|
||||
print(" END Of Import to elastic ", index_name ,"\n")
|
||||
|
||||
|
||||
def iterateJsonFile(self, file_path, isZip=True, limit_pack = -1):
|
||||
if not os.path.exists(file_path):
|
||||
print("file zip:" , file_path , " not exist iterateJsonFile " )
|
||||
return
|
||||
|
||||
if isZip :
|
||||
fileNo = 0
|
||||
with zipfile.ZipFile(file_path, 'r') as zObject:
|
||||
fileNo +=1
|
||||
print("="*10, " zip fileNo: " , fileNo ," iterateJsonFile - | File Numbers:" ,len(zObject.namelist()) , "=" * 10)
|
||||
|
||||
packNo = 0
|
||||
self.counter = 0
|
||||
for filename in zObject.namelist():
|
||||
packNo += 1
|
||||
if limit_pack != -1 :
|
||||
if packNo > limit_pack :
|
||||
print('limit_data iterateJsonFile ', limit_pack)
|
||||
break
|
||||
|
||||
print("index iterateJsonFile :", '=>' , filename )
|
||||
with zObject.open(filename) as file:
|
||||
data = json.loads(file.read())
|
||||
# Yield each entry
|
||||
# yield data
|
||||
yield from ({"source": hit["_source"], "id": hit["_id"]} for hit in data)
|
||||
else :
|
||||
with open(filename, 'r', encoding='utf-8') as file:
|
||||
data = json.loads(file.read())
|
||||
# Yield each entry
|
||||
# yield from (hit for hit in data)
|
||||
#return data
|
||||
yield from ({"source": hit["_source"], "id": hit["_id"]} for hit in data)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def es_iterate_all_documents(self, index, body="", pagesize=250, scroll_timeout="25m", **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user