diff --git a/graph.py b/graph.py new file mode 100755 index 0000000..00a0a93 --- /dev/null +++ b/graph.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import json +import typing +import os + + +def as_graphviz(recipes: dict): + print("digraph G {") + for result, method in recipes.items(): + for variation in method: + for input in variation["input"]: + print(f"{input} -> {result}") + print("}") + + +if __name__ == '__main__': + root = os.path.dirname(__file__) + recipe_root = os.path.join(root, 'data', 'recipes') + + recipes = dict() + + for dirname, dirs, files in os.walk(recipe_root): + for f in files: + path = os.path.join(dirname, f) + name, _ = os.path.splitext(f) + with open(path, 'r') as src: + variations = json.load(src) + + recipes[name] = variations + + as_graphviz(recipes)