38 lines
1014 B
Python
38 lines
1014 B
Python
import os
|
|
import json
|
|
|
|
# Function
|
|
# Get the data from input files
|
|
def Read(folder_path):
|
|
data = []
|
|
|
|
for filename in os.listdir(folder_path):
|
|
if filename.endswith('.json'):
|
|
file_path = os.path.join(folder_path, filename)
|
|
with open(file_path, 'r', encoding='utf-8') as file:
|
|
data.extend(json.load(file))
|
|
return data
|
|
|
|
# Write into output files
|
|
def Write(data, output_file):
|
|
with open(output_file, 'w', encoding='utf-8') as file:
|
|
json.dump(data, file, indent=4)
|
|
|
|
# Path of files need to be read
|
|
folder_path1 = '.\ejde_buffer\Author'
|
|
folder_path2 = '.\ejde_buffer\Article'
|
|
|
|
# Read the data in the files
|
|
Author_data = Read(folder_path1)
|
|
Article_data = Read(folder_path2)
|
|
|
|
# The path of output files
|
|
output_file1 = '.\ejde_buffer\Author_output_file.json'
|
|
output_file2 = '.\ejde_buffer\Article_output_file.json'
|
|
|
|
# Write into files
|
|
Write(Author_data, output_file1)
|
|
Write(Article_data, output_file2)
|
|
|
|
# End
|
|
print("\nData has been written into files.") |