-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_mover.py
25 lines (20 loc) · 707 Bytes
/
data_mover.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
import json
import collections
import sys
def move_data(prev_path, current_path):
with open(prev_path, encoding='UTF8') as f:
prev_data = json.load(f)
with open(current_path, encoding='UTF8') as f:
current_data = json.load(f, object_pairs_hook=collections.OrderedDict)
for key, value in current_data.items():
if key in prev_data:
current_data[key] = prev_data[key]
prev_data.pop(key, None)
else:
print("Key {0} is not in previous data!".format(key))
print(prev_data)
for key, value in prev_data.items():
current_data[key] = value
with open(current_path, "w", encoding='UTF8') as f:
json.dump(current_data, f, ensure_ascii=False, indent=2)
move_data(sys.argv[1], sys.argv[2])