just a dude abiding

Android scripting for fun and profit

Okay the last part isn’t exactly likely given that you can’t directly package a script application as an APK. I doubt you’ll be making much “profit” from it anytime soon. Regardless, ASE support is a great boon to hackers, and allows for a whole new level of customization of your phone.

I decided to organize and prune my book collection the other day, and remembered reading a brief tutorial on scanning barcodes using Python and the ASE. I thought this would be a great chance to learn a bit about ASE and Android in general. Here’s the basic steps I took, hopefully they’ll be of some use to someone.

Despite the instructions which recommend starting with the ASE install, I found it easier to download the python interpreter to the phone first. http://code.google.com/p/android-scripting/wiki/InstallingInterpreters

Then install the most recent version of ASE to your phone (either using the QRCode at http://code.google.com/p/android-scripting/ or downloading the APK straight to your phone).

The ASE site has a fair bit of sample code, so I took the barcode sample and made a few adjustments that will let me track my book collection easier.

The script is admittedly pretty simple: read the barcode, check to make sure we got an actual result, then send it on to the webserver. Make sure to fill in the proper server name before you use the code. For my purposes I was going to be scanning a bunch of books all at once, so I put it in an infinite loop so I didn’t have to relaunch it for every book. To exit the loop simply hit the “back” button on your phone.

Now that we can scan the barcodes locally, we need to do something with them on the server side.

Above is a simple PHP script that will write the ISBNs to a text file. The most important part is parseUPC method, which converts a UPC barcode to an ISBN. If the barcode isn’t formatted as an ISBN it’s left in it’s original format.

And that’s basically it. Drop the PHP code on your web server, make sure the path and server name match in the python script, and you’re off and scanning!

Add in some queries to Amazon ECS or Google Books, and you’re halfway to your own personal version of LibraryThing.