Android barcode scanner in 6 lines of Python code

June 10th, 2009 Matt Cutts Posted in Gadgets/Hack No Comments »

After my last video about using a barcode scanner to add and search books in your library, I was feeling pretty happy. Bar code scanners are pretty cheap--mine cost about $65. But then Google released the Android Scripting Environment (ASE) and it turns out that you don’t even need a bar code scanner. Instead, you can use an Android phone such as the G1.

Just as a proof-of-concept, here’s a barcode scanner written in six lines of Python code:

import android
droid = android.Android()
code = droid.scanBarcode()
isbn = int(code['result']['SCAN_RESULT'])
url = “http://books.google.com?q=%d” % isbn
droid.startActivity(’android.intent.action.VIEW’, url)

Thanks to fellow Googler Vijayakrishna Griddaluru for sending me this sample code. Visiting the resulting url offers the option to add that book to your library:

Android bar code scanner

Pretty easy, huh? You can read all about the new scripting environment. Not only can you scan bar codes, you can use text-to-speech, make phone calls, send text messages, read sensor data, and find your location--all from easy scripts. One person wrote a script to go into silent mode when the phone is placed screen-down on the table. It took less than 20 lines of code, and that’s including comments!

The Android Scripting Environment should make fun projects even easier. Brad Fitzpatrick wrote about using his Android phone to open his garage door automatically when his motorcycle gets close to home. Now those sorts of projects are even easier to write. :)

AddThis Social Bookmark Button

Search your bookshelf with a $65 barcode scanner

June 7th, 2009 Matt Cutts Posted in Gadgets/Hack No Comments »

(Okay, if TechCrunch wrote about my video then I should probably at least do a blog post too.)

Last year I suggested potential Summer of Code projects and one of my favorite suggestions was “How about a good open-source program to manage your book library? Something like the Delicious Library program, but that works with Linux?” In the blog comments, Colin Colehour left an excellent comment: “Matt, Can’t you use Google Books to keep track of your book library at home? You can add books that you own to the ‘my library’ list and then export that as an xml file and they have RSS feeds.”

The suggestion was so obvious that I smacked my head. Why install software at all when a website will store the data for you? The only problem was how to tell Google which books I own. Well, there’s a neat hack for this too: Amazon carries the Adesso NuScan 1000 bar code scanner for $65.44 with free shipping. I’m sure you can get barcode scanners for cheaper (anyone remember the CueCat scanner that was free?), but the Adesso had good reviews.

With that, adding your books to Google’s My Library feature is simplicity itself--the Google Books team has tweaked the workflow so that you can barcode scan and add lots of books very quickly. Here’s the video to demonstrate:

Why would you record which books you own in the first place? The immediate reason is that you can run full-text searches against the books in your library. That’s right: just by scanning bar codes, you can search over the text of books you own. Down the road, I can easily imagine other uses. Wouldn’t it be great if you could upload your list of books to Amazon, and it would automatically suggest other books you should read? Or avoid suggesting books that you already own? Josh Lowensohn mentions another great reason to do this: it creates a record for insurance purposes.

Once you have your book list, there are social networks for book lovers such as Goodreads and LibraryThing. And please note: this isn’t the only way to scan your books. Delicious Library 2 is $40 commercial software for the Mac that can use your Mac’s built-in webcam.

Special thanks to Michael ‘Wysz’ Wyszomierski for recording and producing this video. I love that he showed the computer’s screen and showed an “action shot” of scanning the books.

AddThis Social Bookmark Button





OK!