-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-up-old-data.py
More file actions
executable file
·41 lines (34 loc) · 1.06 KB
/
fix-up-old-data.py
File metadata and controls
executable file
·41 lines (34 loc) · 1.06 KB
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
41
#!/usr/bin/env python3
import json
from sys import argv
if len(argv) != 3:
print("usage: {} <input file> <output file>".format(argv[0]))
exit(1)
# Load
dump = None
with open(argv[1], "r") as fp:
records = json.load(fp)
print("Read {} records from {}".format(len(records), argv[1]))
# Ouptut Statistics
model_types = {}
for record in records:
model = record['model']
if model not in model_types:
model_types[model] = 0
model_types[model] += 1
for k in sorted(model_types.keys()):
print(k, model_types[k])
# Filter and munge
output = []
for record in records:
model = record['model']
if model.startswith('planner.') or model in ['auth.user']:
output.append(record)
# if model == 'contenttypes.contenttype':
# del record['fields']['name']
# print(record['fields']['app_label'], record['fields']['model'])
# output.append(record)
# Output result
with open(argv[2], "w") as fp:
print("Writing {} records to {}".format(len(output), argv[2]))
json.dump(output, fp, sort_keys=True, indent=4)