-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_combine_data_files_info.py
33 lines (26 loc) · 1.01 KB
/
04_combine_data_files_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sys
import os
import io
import json
import xlwt
if len(sys.argv) < 2:
print ('\n\nusage1: \n\n>>>python ' + sys.argv[0] + ' {dir with data files} \n\n')
exit()
places_search_dir_path = sys.argv[1]
if not os.path.isdir(places_search_dir_path):
print (str('%s is not a directory' % places_search_dir_path))
composite_data_file_name = 'composite_data_file.json'
dict = {}
for filename in os.listdir(places_search_dir_path):
if filename.endswith(".json"):
print (filename)
with open(str(places_search_dir_path) + "/" + str(filename)) as json_data:
place_coord_file_data = json.load(json_data)
# print json.dumps(coord_places_data, indent=2)
for key in place_coord_file_data:
dict[key] = place_coord_file_data[key]
# write the data into a json file
with io.open(composite_data_file_name, 'w', encoding='utf8') as json_file:
data = json.dumps(dict, indent=4, ensure_ascii=False)
# json_file.write(unicode(data))
json_file.write(data)