Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions nodes/PythonFunction/script.template.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import atexit;
import fire
import json
import os;
import sys
from pathlib import Path

@atexit.register
def cleanup():
if os.path.exists(__file__):
os.remove(__file__);
# end if
# end cleanup()

def snippet_runner(items: list, env_vars: dict) -> list:
# ...code snippet
# should return items
# <%- codeSnippet %>
pass
# ...code snippet
# should return items
# <%- codeSnippet %>
pass

def main(json_path: str, env_vars: dict = {}) -> None:
with open(Path(json_path), 'r') as json_file:
items: list = json.load(json_file)
new_items = snippet_runner(items, env_vars)
assert type(new_items) is list or isinstance(new_items, list), "code snippet should return a list"
# print('```', json.dumps(new_items), '```')
# sys.stdout.write(json.dumps(new_items))
sys.stderr.write(json.dumps(new_items))
exit(0)
with open(Path(json_path), 'r') as json_file:
items: list = json.load(json_file)
new_items = snippet_runner(items, env_vars)
assert type(new_items) is list or isinstance(new_items, list), "code snippet should return a list"
# print('```', json.dumps(new_items), '```')
# sys.stdout.write(json.dumps(new_items))
sys.stderr.write(json.dumps(new_items))
exit(0)


if __name__ == "__main__":
fire.Fire(main)
fire.Fire(main)