-
Notifications
You must be signed in to change notification settings - Fork 18
/
dedupe.py
41 lines (31 loc) · 1021 Bytes
/
dedupe.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
33
34
35
36
37
38
39
40
import json
from collections import OrderedDict
def load_json_file(file_path):
with open(file_path, "r") as f:
return json.load(f)
def save_json_file(file_path, data):
with open(file_path, "w") as f:
json.dump(data, f, indent=2)
def main(dry_run: bool=False):
file_path = "mlva-templates-2.0-deduped.json"
output_path = "templates_2_3_rc1.json"
data = load_json_file(file_path)
version = data["version"]
portainer_templates = data["templates"]
cleaned_templates = OrderedDict()
for template in portainer_templates:
title = template["title"]
if title not in cleaned_templates:
cleaned_templates[title] = OrderedDict(template)
else:
break
cleaned_data = {
"version": "2",
"templates": list(cleaned_templates.values())
}
if dry_run:
print(json.dumps(cleaned_data, indent=2))
return
save_json_file(output_path, cleaned_data)
if __name__ == "__main__":
main()