Skip to content

Instantly share code, notes, and snippets.

@michaelrice
Created January 23, 2020 03:23
Show Gist options
  • Save michaelrice/8f48061940f84f2fc25241d058e87ff2 to your computer and use it in GitHub Desktop.
Save michaelrice/8f48061940f84f2fc25241d058e87ff2 to your computer and use it in GitHub Desktop.
Python script to generate a catalog file for digital rebar
import json
with open("rackn.json") as jf:
data = json.load(jf)
version = "stable"
new_file = "new_catalog.json"
items = data['sections']['catalog_items']
new_catalog = {}
new_catalog['meta'] = data['meta']
new_catalog['sections'] = {}
new_catalog['sections']['catalog_items'] = []
for k, v in items.items():
if v['Version'] == version:
new_catalog['sections']['catalog_items'].append(v)
with open(new_file, 'w') as f:
json.dump(new_catalog, f, indent=4, sort_keys=True)
print("done")
@michaelrice
Copy link
Author

using an existing catalog (named rackn.json) the above script would pull all catalog items labeled at "stable" out and build a new catalog named "new_catalog.json". This is very helpful with multi site manager and can reduce the size of your catalog significantly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment