Created
January 23, 2020 03:23
-
-
Save michaelrice/8f48061940f84f2fc25241d058e87ff2 to your computer and use it in GitHub Desktop.
Python script to generate a catalog file for digital rebar
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
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.