Command line candy for PYBOSSA
PYBOSSA is a great framework, however we were lacking a nice command line tool to interact with it.
For this reason, after providing several different scripts to create projects, add tasks, etc, etc. I’ve decided to finally create a simple command line tool to master the PYBOSSA API.
As I wanted to create a powerful but simple tool to manage PYBOSSA projects via the command line, I looked for different solutions: argparse, docopt, etc. From all the available solutions I found Click from Armin Ronacher and after trying it I was simply AMAZED.
Click is really powerful, simple and its feature for nesting commands is incredible.
Thanks to Click I’ve managed to develop a command line tool for PYBOSSA in two days, that behaves more or less like git with commands, sub-commands and –help options to make your life much simpler!
Installing pbs is very simple. Just install it with pip with the following command:
Then all the magic happens .
I’ve designed pbs to be very flexible, so all the options can be passed as arguments, giving you all the flexibility that you could need.
One of the key aspects that I love from pbs is the possibility of having a config file for storing my credentials for different PYBOSSA servers. This simplifies my life, reduces the ammount of typing and I don’t have to check all the time my API-KEY in the servers that I’m using :-)
The config file is very simple. It’s just a file named .pybossa.cfg that looks something like this:
By default, pbs will use the default section, but if you want to authenticate against another server, all you’ve to do is to pass the following command line option: –credentials anotherserver. Done!
You don’t actually need that file, but if you are working a lot with PYBOSSA I would recommend you to create it. It’s really amazing.
Now that we’ve pbs configured all we’ve to do is to create a project. Creating a project is as simple as always. All you need is a project.json with something like this:
Then, if you run pbs from the same folder where that file has been created, all you’ve to do for creating a project is running the following command:
Two words, and your project is created!
Now that we’ve our project available in the server, we can add tasks to it. With pbs I wanted to allow users to import tasks from PYBOSSA servers without having to do nothing special. If you visit a project in Crowdcrafting you will see that right now PYBOSSA allows you to download tasks as files in two different formats: CSV and JSON.
Once you’ve downloaded one set of tasks from Crowdcrafting, pbs allows you to re-use the data, as all the projects are using an open-data license. Cool, right?
How do you re-use the tasks’s file? If you’ve downloaded the tasks in CSV format, all you have to do is running the following command:
Done! You’ve even a progress bar and if you have more than 300 tasks, pbs will auto enable the throttling to respect the PYBOSSA limits of the server. I love this ;-)
Now, all we’ve to do is to add the tutorial, task presenter and long description.
For adding those files to the project, you can have those files created in a folder, with the following names:
If those file names exist where you are running the command, then you don’t have to type almost anything, just this command:
Done! Quick, fast and simple. If you are testing something new, or if you want to reuse a template from another project, all you’ve to do is tell it to pbs:
In the following video you can see how quickly you can create a project in Crowdcrafting (or any PYBOSSA server) using pbs with the Flickr Person Finder template.
PS: I almost forgot to mention it: everything is open source and you can check the source code here.