How to run a QPython script regularly?

854 views
Skip to first unread message

chris.b...@googlemail.com

unread,
Jan 27, 2016, 1:08:36 PM1/27/16
to Automate
Hey, I really like Automate! Unfortunately scripting complex tasks quickly becomes bothersome to impossible without a proper scripting or programming language. For these tasks I had planned to use Python with the QPython Android application and the Plyer/Pyjnius module. I would run these scripts then regularly with an Automate flow and possibly capture the output or call the scripts with various parameters. My question is: How exactly would I do that? There's the "App start" block -- but actually configuring it to work with QPython seems confusing or impossible without deeper knowledge of the Android API. Could someone chime in who has attempted similar things before? Maybe the developer?

Thank you,
Chris

Henrik "The Developer" Lindqvist

unread,
Jan 27, 2016, 2:25:36 PM1/27/16
to Automate, chris.b...@googlemail.com
QPython likely installs an python binary which you can start using the Shell command block.

chris.b...@googlemail.com

unread,
Jan 28, 2016, 8:42:15 AM1/28/16
to Automate, chris.b...@googlemail.com
Yes it does, and I considered doing that but I wanted to do it the right way (or what I assumed the right way was). The problem when trying to execute the binary directly is, that I have to run it with the root account due to various system files that need to be loaded (I think). I tried changing the permissions only for the /data/data/... directory but that unfortunately didn't work -- certain libraries can't be loaded then. I can't move it to the sdcard and execute it there, because that's not an unix filesystem -- and even if it was, I would still need to be root to run the scripts and load the other libraries (I think). So it works basically, but all my scripts run as root, which is a disaster waiting to happen.

Henrik "The Developer" Lindqvist

unread,
Jan 28, 2016, 9:05:47 AM1/28/16
to Automate, chris.b...@googlemail.com
You'll have to investigate if it possible to start a script in QPython using an broadcast or activity intent.

chris.b...@googlemail.com

unread,
Jan 28, 2016, 9:25:01 AM1/28/16
to Automate, chris.b...@googlemail.com
I think this is what I'm looking for: https://github.com/qpython-android/AndroidApp-with-qpython-API/blob/master/app/src/main/java/org/qpython/sample/MainActivity.java -- So basically choose the .action.MPyApi as the activity, and then use {"pycode": "<my code here>"} in the extras dictionary? Do you know what is meant with line 80? I'd prefer not to have manually escape every character in the PyCode string, alternatively I'd have to save my code as a JSON string and maybe decode it to populate the dictionary? I'm sorry, I'm a bit at a loss here regarding the Android ecosystem and its inner workings.

Henrik "The Developer" Lindqvist

unread,
Jan 28, 2016, 5:42:22 PM1/28/16
to Automate, chris.b...@googlemail.com
What that code does, is similar to using the App start block with...
Package: com.hipipal.qpyplus
Activity class: com.hipipal.qpyplus.MPyApi
Action: com.hipipal.qpyplus.action.MPyApi
Extras: { "app":"myappid", "act":"onPyApi", "flag":"onQPyExec", "param":"", "pycode":"<code goes here>" }

You should likely use the File read block to read the Python code (replacing the "<code goes here>" literal), otherwise you'll have to escape the code all the ", \n, {, etc.
Reply all
Reply to author
Forward
0 new messages