p = Popen(["/usr/bin/python3", '/path/to/py3script.py', 'Arg1','Arg2'], stdin=PIPE, stdout=PIPE, bufsize=1, universal_newlines=True)
val = p.stdout.readline()
FlyingDiver wrote:Unfortunately, it does not appear that you can include arguments with the Indigo action.
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
print(sys.argv[0], sys.argv[1], sys.argv[2])
/Users/jay/Projects/Python/test_py3_script.py first_arg second_arg
ryanbuckner wrote:One more thing I had to do that wasn’t obvious. The directions using shell paths in Indigo say to use backslash as escape characters for spaces. This errored in the Indigo interface. Using quotes around the path worked.
/Users/jay/Projects/Python\ Test/test\ py3\ script.py first_arg second_arg
FlyingDiver wrote:Jay - maybe update the description text to include that info?
jay (support) wrote:ryanbuckner wrote:One more thing I had to do that wasn’t obvious. The directions using shell paths in Indigo say to use backslash as escape characters for spaces. This errored in the Indigo interface. Using quotes around the path worked.
Odd, I can't reproduce that. I used this in a run shell script action (altered from the above post) and it worked:
- Code: Select all
/Users/jay/Projects/Python\ Test/test\ py3\ script.py first_arg second_arg
import subprocess
# first grab the lat/long from indigo and convert to string
lat = str(indigo.devices[105421725].states["position_lat"]) # State "position_lat" of "Ryan's BMW 540ix" from the BMW Connected Plugin
long = str(indigo.devices[105421725].states["position_lon"]) # State "position_lon" of "Ryan's BMW 540ix"' from the BMW Connected Plugin
# call the subprocess with 2 arguments and store in p
p = subprocess.check_output(["/usr/bin/python3", '/Library/Application Support/Perceptive Automation/Python2-includes/bmwgeo.py', lat, long], stderr=subprocess.STDOUT)
#receive the output and store in indigo variable
indigo.variable.updateValue(339870612, value=p)
#!/usr/bin/python3
from shapely.geometry import Point, Polygon
import sys
def main():
#define the polygon fence
coords = [
(39.008234937234256, -77.37684452531161),
(39.00809324520176, -77.37627518191934),
(39.00733602026089, -77.37671994280922),
(39.0076547326009, -77.37724949835487)
]
homeFence = Polygon(coords)
lat = float(sys.argv[1]) #39.00777
long = float(sys.argv[2]) #-77.37668600000001
#create a point for your car
bmw = Point(lat, long)
#return a true/false to see if your car is inside the Polygon
print("{}".format(bmw.within(homeFence)), file = sys.stdout)
if __name__ == "__main__":
main()
indigo.variable.updateValue(339870612, value=p.rstrip())
Users browsing this forum: No registered users and 3 guests