Last active
May 7, 2019 00:32
-
-
Save raganmd/76aaf3414612908ec253f2e8f70508d0 to your computer and use it in GitHub Desktop.
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 | |
def load_store_json(target_file, storage_op, target_key, storage_name): | |
''' | |
A Helper function that reads JSON from disk | |
Args | |
--------------- | |
target_file (file path): | |
> a path to a .json file on disk. This is where the file will | |
> be read from. | |
storage_op (TouchDesigner operator): | |
> the target operator where we will store the dictionary. | |
target_key (str): | |
> the string key we want to pull from our JSON file. | |
storage_name (str): | |
> the string name we want to use for storage. | |
Returns | |
--------------- | |
None | |
''' | |
# open the json file | |
json_file = open(target_file, 'r') | |
# create a dictionary out of our json file | |
json_dict = json.load(json_file).get(target_key) | |
# store our dictionary in the target op | |
storage_op.store(storage_name, json_dict) | |
# close the file | |
json_file.close() | |
# example use | |
target_file = '{}/cues.json'.format(project.folder) | |
storage_op = op('base_example') | |
target_key = 'presets' | |
storage_name = 'presets' | |
load_store_json(target_file, storage_op, target_key, storage_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment