Craig in feed form

Archive for the 'Distractions' Category An orange feed icon

Google Books android script

July 29th, 2010

The script below lets you scan multiple book barcodes and add the books directly to your Google Library.

Since getting a Nexus One I’ve been wanting to dabble with programming something for it, Java seemed far too hard. However, I quickly came across Scripting Layer for Android (SL4A) which lets you write quick scripts in a variety of languages; including my favourite, Python. The next challenge was to actually come up with a simple project to get my hands dirty.

Matt Cutts wrote a simple script that scans a barcode and pulls up its Google Books page, from which you can then click the ‘add to my library’ button, but this seemed far too clumsy and slow to me, so I settled on improving it. The script now lets you scan multiple books in series and then add them to your Google library by making use of the Google Books Search API.

See the code (public domain) below:

import android
from gdata.books.service import BookService
import gdata.books

email = 'youremail@gmail.com'
password = 'yourpassword'

droid = android.Android()

def dialog(items):
  title = 'Another?'
  droid.dialogCreateAlert(title)
  droid.dialogSetItems(items)
  droid.dialogSetPositiveButtonText('Add')
  droid.dialogSetNegativeButtonText('Exit')
  droid.dialogSetNeutralButtonText('Upload')
  droid.dialogShow()
  response = droid.dialogGetResponse().result
  return response['which']

def add_from_queue(self):
   for k,b in self.queue.items():
      self.add_item_to_library(b)
   return(True)

def get_by_barcode(self):
   (id, result, error) = droid.scanBarcode()
   if result is not True:
      return(False)
   isbn = int(result['extras']['SCAN_RESULT'])
   q = 'ISBN'+str(isbn)
   b = self.search(q, feed=self.ITEM_FEED).entry[0]
   self.queue[b.dc_title[0].text] = b
   return(True)

gdata.books.service.BookService.get_by_barcode = get_by_barcode
gdata.books.service.BookService.add_from_queue = add_from_queue
gdata.books.service.BookService.queue = {}
gdata.books.service.BookService.ITEM_FEED = gdata.books.service.ITEM_FEED

service = gdata.books.service.BookService()
service.ClientLogin(email, password)

service.get_by_barcode()

i = True
while i:
  response = dialog(service.queue.keys())

  if response == 'positive':
     service.get_by_barcode()

  elif response == 'neutral':
     service.add_from_queue()
     service.queue = {}

  else:
     i = False

droid.exit()

Updated: Thanks to sjb for pointing out a bug in the code; now fixed.

Genuine excuse

July 26th, 2007

Now that I’m doing real paid work I have less time to even think of things I might like to write in my blog. Here I am anyway though, blogging in my lunch break.

As far as work goes I’m still slogging away on the same project. Battling with conflicting interests and bloody politics… The project would be a doddle if we weren’t all so infuriatingly human about everything, but alas I don’t see any progress being made on that front for a long time. As I fear is the case with all knowledge management work, the project involves simplifying and making understandable and usable the complexity that is society (society in what ever form you happen to be looking at).

The first random thing I’d like to write about is probably another item in a growing catalogue of evidence that I’m obsessed with everything Google. For a while now I’ve been using their mapping tool (cunningly named Google Maps) to find my way about and for all those other occasions one needs to reference a map. Obviously one of the big uses is getting directions from one place to another. One aspect of which annoys me across all mapping tools is the inability to customise your route… when you know what they have suggested is just plain wrong! Well Google have done it again, now you just click on the route and drag it to another road, it will recalculate the route for it.

Along similar lines of “things you’ve always wanted”, I’ve started thinking about how to make my own piece of writing software. You might shout angrily that it is a silly idea because so many already exist… and you’re right. Unfortunately none of them really suit the way I like to write. I want to be able to separate out the ‘content’ I produce from the document and from any kind of presentation. I want a semantic writing tool. I’ll write more about it in time, as my ideas come together.

What am I reading?

December 25th, 2006

I’ve always enjoyed sharing what I’ve enjoyed reading, of my friends most if not all have probably fallen foul of this tendency of mine through being offered books or having a newspaper shoved under their noses. Why am I going into all of this now? Well, for some time I’ve been sharing items using Google’s feed reader and it only just occurred to me that there isn’t really any sense in doing it unless I’m going to tell people about it!? So here is my collection of shared articles.

I’ll probably try to work it directly into this blog (or somewhere else on the website) at some point, but that will have to wait for a little while.

Oh, and a Merry Christmas to the Christians out there.

Power of constraints

November 3rd, 2006

I love the various little games that keep getting thrown up in semi-scientific contexts that show how complex (and at the same time simple) our minds really are, here is an example I enjoyed:

I’m thinking of three words: one means “a mythical being”, the second is “the name of a building material”, and the third is “a unit of time”, What words do I have in mind?

It’s not difficult to think of three words that fit the descriptions, but it is unlikely you’ll pick the three I had in mind. Now try a second task:

This time I’m looking for rhyming words. I’m thinking of three words: one rhymes with “post”, the second with “eel” and the third with “ear”. What words am I thinking of?

Again, you can think of three words which match the descriptions easily, but which ones did I have in mind, last but not least:

Suppose I tell you the words I seek are the same in both tasks: What is a word that means a mythical being and rhymes with “post”? What word is the name of a building material and rhymes with “eel”? And what word is a unit of time and rhymes with “ear”?

Now the task is easy, the combination of just two constraints reduces the selection until there are only three words which fit… “ghost”, “steel” and “year”!

This was taken from a book I’m rather enjoying called “The Design of Everyday Things” by Donald A. Norman which is a bit of an engineers book to be honest, but is good bed time reading all the same (or whisky supping reading at least!)

(and no this isn’t one of those horrible pay per post things, if you want to read it try a library :P )

Archives

Categories