I am trying to create a twitter bot that posts randomized content, similar to OreoBot, that uses processing. I have the processing script (made with python mode) that creates the image and I know how to post the image, now all I have to do is make the python script run the processing script and get a string of text from it when it finishes running, how do I do that?
Sorry, I’m not familiar with OreoBot. It sounds like you want to post an image and some text you’ve generated with Processing?
You can do this with the command-line version of Processing.py. You can download it here:
You would add something like this to the end of your sketch file:
... saveStrings('text.txt', ['blah blah blah']) saveFrame('image.jpg') exit()
If you run this sketch from the command line, Processing will save the string to a file named
text.txt, and the image to a file named
java -jar processing-py.jar sketch_name.pyde
exit() function closes the display window (which will probably appear and disappear before you can even see it, anyhow). * There’s probably a way to do this completely headless – i.e. no
exit() function required – but I’m not sure how to do this with processing.py’s command-line version.
If the above is working fine, add the following code to your bot script, which calls the command-line version of Processing from Python, then waits for the image to be generated before proceeding:
import os import time os.system('java -jar processing-py.jar sketch_name.pyde') while not os.path.exists('image.jpg'): time.sleep(1) # do twitter stuff here ...
You’ll have to substitute the paths and filenames to work with your project. You can read in the text file using the standard Pyhton
with open(... approach.
Yes, I’m going to generate an image and some text using processing
I did that and it returned “Error: Unable to access jarfile processing-py.jar”
Edit: I don’t know where is processing-py.jar
Your file path(s) are wrong. There are different ways to fix this. This method might be the easiest to explain –
You’ve downloaded and extracted a folder containing the command-line version of processing.py. Maybe just place your python script and .pyde file in here.
processing.py-30__ │ ... │ processing-py.jar │ ... │ python_script.py │ sketch_name.py
It should work now (everything can be accessed using relative paths).