Last active
April 30, 2019 13:38
-
-
Save asmoore82/1f4e904b7343da7bfcf527fe5586c406 to your computer and use it in GitHub Desktop.
Python script to take the JSON export tree out of FileWave and "flatten" it to a simple list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Copyright (c) 2018 Alamance-Burlington School System, MIT License | |
import json | |
import os | |
fwo_clients = 'all-clients.json' | |
fwo_min = 'all-clients.min.json' | |
fwo_flat = 'all-clients.flat.json' | |
fw_skip_groups = ('/LDAP Groups',) | |
def walker(j, path=''): | |
if isinstance(j, list): | |
for i in j: | |
for x in walker(i, path): | |
yield x | |
elif isinstance(j, dict): | |
t = j.get('type') | |
n = j.get('name') | |
if n: | |
n = '{}/{}'.format(path, n) | |
if t == 'client': | |
yield n | |
elif t == 'clone': | |
yield '{}@'.format(n) | |
elif t == 'group': | |
yield '{}/'.format(n) | |
if n not in fw_skip_groups: | |
for x in walker(j.get('children'), n): | |
yield x | |
if __name__ == "__main__": | |
if os.path.isfile(fwo_clients): | |
with open(fwo_clients, 'r') as f: | |
j = json.load(f) | |
with open(fwo_min, 'w') as f: | |
json.dump(j, f) | |
j = list(walker(j)) | |
with open(fwo_flat, 'w') as f: | |
json.dump(j, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment