404background / node-red-contrib-python-venv

Node for python virtual environment
MIT License
9 stars 3 forks source link

New STDIN mode #21

Open Alkarex opened 2 months ago

Alkarex commented 2 months ago

New continous mode using STDIN to pass messages. Useful for larger / faster payloads.

Related to https://github.com/404background/node-red-contrib-python-venv/pull/20 (sorry for the poor coordination on my side)

Example of Python code:

import json
import sys

for line in sys.stdin:
    msg = json.loads(line)
    msg['payload'] = msg['payload'] * -1
    print(json.dumps(msg, separators=(',', ':')), flush=True)
flows.json ```json [ { "id": "f14c248431d474e8", "type": "inject", "z": "f6f2187d.f17ca8", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 130, "y": 260, "wires": [ [ "8be43bb7c337f2b3" ] ] }, { "id": "b50cd141069d9975", "type": "debug", "z": "f6f2187d.f17ca8", "name": "debug 1", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 560, "y": 260, "wires": [] }, { "id": "8be43bb7c337f2b3", "type": "venv", "z": "f6f2187d.f17ca8", "name": "", "code": "import json\nimport sys\n\nfor line in sys.stdin:\n msg = json.loads(line)\n msg['payload'] = msg['payload'] * -1\n print(json.dumps(msg, separators=(',', ':')), flush=True)\n", "x": 350, "y": 260, "wires": [ [ "b50cd141069d9975" ] ] } ] ```
Alkarex commented 2 months ago

@FrederikPM will take over as am on my way to some vacations 🏖️