Importing pipista modules in Editorial
Lets face it, the Editorial App is a fantastic text/Markdown editor. It’s incredibly powerful with scripting abilities. But one of the most amazing tool for a power user is the ability to write Python scripts that can do almost anything. There are a lot of modules included with Editorial, but how do you add a library if it’s not included? There is a script for Editorials sister application Pythonista, that makes it easy to add modules, and you can use that for importing libraries to Editorial as well. The script is called Pipista.
How to import a python module in Editorial
I needed to import the python-wordpress-xmlrpc library for uploading images to the WordPress Media Library on my blog directly from Editorial so the images ends up in the media section in WordPress. I didn’t want to use FTP or SFTP. So here is how to import (and use) that module.
First you need Pipista. I’m using version 2 unstable because it unzips the file automatically, so everything is done for you. It also puts the modules in a separate directory so it doesn’t clutter up your filesystem.
- First we need to get the pipista script into Editorial. So go to the pipista GitHub page and download the script as a text file. (You can just select the text and paste it into a text file.)
- Name the file pipista.py
- Upload the pipista.py file to Editorial with iTunes
- Go to the Console and write the following lines. Enter each line separately and end with return.
You should now have the module installed and ready to go.
Using the new module in your scripts
Because the directory with the modules aren’t in the system path, you need to add that at the top of your script before trying to import a module. Just write
[cc lang=”python”]sys.path += [os.path.join(os.getcwd(), ‘../../../Documents/pypi-modules’)][/cc]
And now you can import you’re newly installed modules.
[cc lang=”python”]from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.compat import xmlrpc_client
from wordpress_xmlrpc.methods import media, posts[/cc]
And there you go!