call a .py file from within Indigo and supply an argument

Posted on
Mon Aug 15, 2016 6:36 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

call a .py file from within Indigo and supply an argument

I want to call ./bmwpost.py 'LOCK_DOOR' from Indigo but I'm running into some issues and I'd love some help:

1) It appears I have python 2.6 and 2.7 installed based on an upgrade to El Capitan. My requests module will not run in 2.6 for some reason and I'm not sure how to fix that. Therefore a call from terminal runs fine, but tells me requests has not been installed when trying to run from Indigo

2) My workaround (is very newb but it kinda works, is to have Indigo launch a terminal window and call the .py with arguments, then close the terminal window. This works, however it has some real downsides:
a) there's no interaction with Indigo to populate variables , log, or anything else
b) it's just an API call to BMWs API but it takes the IndiogServer offline for about 30-50 seconds while it's running.

I'm sure this is all easy, but I'm new in the python environment so I would appreciate some detailed help if changing paths or profiles is involved.

Thanks in advance!!!!
Last edited by ryanbuckner on Mon Aug 15, 2016 6:58 pm, edited 1 time in total.

Posted on
Mon Aug 15, 2016 6:48 pm
FlyingDiver offline
User avatar
Posts: 7217
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: How do I call a .py file with an argument from Indigo

Code: Select all
sudo easy_install-2.6 pip
sudo pip2.6 install requests

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Aug 15, 2016 8:12 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: call a .py file from within Indigo and supply an argumen

Thanks so much! That helped.

Now how can I call that file and send an argument :

I want to call
Code: Select all
python /My Path/bmwpost.py 'LOCK_DOOR'

Posted on
Tue Aug 16, 2016 6:03 am
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: call a .py file from within Indigo and supply an argumen

Also, if you are willing to help more (thank you)!When calling from Indigo, If I try to import bmw.py from another script it throws an import statement. From terminal it works.

Posted on
Tue Aug 16, 2016 6:12 am
FlyingDiver offline
User avatar
Posts: 7217
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: call a .py file from within Indigo and supply an argumen

Need to see the actual error messages, and maybe the scripts as well.

I don't think there's a way to provide arguments to an external script called from Indigo. But I'm not sure since I don't use any. If it was me, I'd edit the script to either not need the argument or to get it from an Indigo variable.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Tue Aug 16, 2016 7:25 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: call a .py file from within Indigo and supply an argumen

[edit] added more code
Code: Select all
import subprocess

# var_name1 2 are the input variables
p1 = indigo.variables["var_name1"].value
p2 = indigo.variables["var_name2"].value

ret=subprocess.Popen("/usr/bin/python  /users/yourid/ypgm "+p1+" "+ p2,shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)).communicate()

## result result is name of variable for the return value
indigo.variable.updateValue["result",ret[0]]





inside your py program
Code: Select all
import sys
p1= sys.argv[1]  # these are strings
p2 = sys.argv[2]
out= p1+p2
print " this is your output " + out


Then ret[0] has the std out = "this is your output " + out
and ret[1] std err output


Sent from my iPhone using Tapatalk

Posted on
Tue Aug 16, 2016 9:03 am
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: call a .py file from within Indigo and supply an argumen

Thanks all!

I have the py accepting and using the arguments. I'm struggling on the call to the .py from Indigo.

In terminal I would type ./bmwpost.py 'LOCK_DOOR'

Posted on
Tue Aug 16, 2016 9:37 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: call a .py file from within Indigo and supply an argumen

You need to use the full path. Like in the example

When opening a shell from indigo it does not know your path.


Sent from my iPhone using Tapatalk

Posted on
Tue Aug 16, 2016 9:39 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: call a .py file from within Indigo and supply an argumen

If your pgm is in your home dir it would be
/users/yourid/bmwpost.py lock_door


Sent from my iPhone using Tapatalk

Posted on
Tue Aug 16, 2016 10:55 am
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: call a .py file from within Indigo and supply an argumen

much appreciated. I'll give it a shot.

Posted on
Fri Aug 19, 2016 6:22 am
Gusten offline
Posts: 171
Joined: Dec 30, 2015
Location: Sweden, Gothenburg

Re: call a .py file from within Indigo and supply an argumen

Hi
Is there anyway you can share the .py script?

I am in a similar situation and would like to see the script so i can understand and mayby solve my issues

Thanx

Martin

Posted on
Tue Oct 11, 2016 8:41 am
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: call a .py file from within Indigo and supply an argumen

Happy to share.

You can find the .py here:https://github.com/edent/BMW-i-Remote

instructions on how to get your Auth Codes for the API here : https://shkspr.mobi/blog/2015/11/reverse-engineering-the-bmw-i3-api/

What I'm struggling with is probably simple. Just getting the .py to run as an attachment.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests

cron