<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Craig Loftus &#187; Books</title>
	<atom:link href="http://craigloftus.net/blog/category/books/feed/" rel="self" type="application/rss+xml" />
	<link>http://craigloftus.net/blog</link>
	<description></description>
	<lastBuildDate>Tue, 25 Oct 2011 09:55:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Google Books android script</title>
		<link>http://craigloftus.net/blog/2010/07/29/google-books-android-script/</link>
		<comments>http://craigloftus.net/blog/2010/07/29/google-books-android-script/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 08:49:02 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Distractions]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://craigloftus.net/blog/?p=71</guid>
		<description><![CDATA[The script below lets you scan multiple book barcodes and add the books directly to your Google Library. Since getting a Nexus One I&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>The script below lets you scan multiple book barcodes and add the books directly to your Google Library.</p>
<p>Since getting a Nexus One I&#8217;ve been wanting to dabble with programming something for it, Java seemed far too hard. However, I quickly came across <a href="http://code.google.com/p/android-scripting/">Scripting Layer for Android</a> (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.</p>
<p>Matt Cutts wrote a <a href="http://www.mattcutts.com/blog/android-barcode-scanner/">simple script</a> that scans a barcode and pulls up its Google Books page, from which you can then click the &#8216;add to my library&#8217; 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 <a href="http://code.google.com/apis/books/">Google Books Search API</a>.</p>
<p>See the code (public domain) below:</p>
<blockquote>
<pre>
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()
</pre>
</blockquote>
<p><strong>Updated:</strong> Thanks to sjb for <a href="http://groups.google.com/group/android-scripting/browse_thread/thread/6bcda21978b49f2#msg_73ecc35dec8b0d8d">pointing out</a> a bug in the code; now fixed.</p>
]]></content:encoded>
			<wfw:commentRss>http://craigloftus.net/blog/2010/07/29/google-books-android-script/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>What am I reading?</title>
		<link>http://craigloftus.net/blog/2006/12/25/what-am-i-reading-2/</link>
		<comments>http://craigloftus.net/blog/2006/12/25/what-am-i-reading-2/#comments</comments>
		<pubDate>Mon, 25 Dec 2006 10:57:10 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Distractions]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://craigloftus.net/blog/2006/12/25/what-am-i-reading-2/</guid>
		<description><![CDATA[I&#8217;ve always enjoyed sharing what I&#8217;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&#8217;ve been sharing items using Google&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always enjoyed sharing what I&#8217;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&#8217;ve been sharing items using <a href="http://www.google.com/reader/" title="The homepage of Google's feed reader tool">Google&#8217;s feed reader</a> and it only just occurred to me that there isn&#8217;t really any sense in doing it unless I&#8217;m going to tell people about it!?  So here is my <a href="http://www.google.com/reader/shared/02291823998085059755" title="A page containing posts I've thought others might like to read">collection of shared articles</a>.</p>
<p>I&#8217;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.</p>
<p>Oh, and a Merry Christmas to the Christians out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://craigloftus.net/blog/2006/12/25/what-am-i-reading-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Power of constraints</title>
		<link>http://craigloftus.net/blog/2006/11/03/power-of-constraints/</link>
		<comments>http://craigloftus.net/blog/2006/11/03/power-of-constraints/#comments</comments>
		<pubDate>Fri, 03 Nov 2006 21:28:12 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Distractions]]></category>

		<guid isPermaLink="false">http://craigloftus.net/blog/2006/11/03/power-of-constraints/</guid>
		<description><![CDATA[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&#8217;m thinking of three words: one means &#8220;a mythical being&#8221;, the second is &#8220;the name of a building material&#8221;, and the [...]]]></description>
			<content:encoded><![CDATA[<p>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:</p>
<blockquote cite="http://www.amazon.com/gp/product/0465067107/ref=pd_cp_b_title/102-1452992-3960136"><p>I&#8217;m thinking of three words: one means &#8220;a mythical being&#8221;, the second is &#8220;the name of a building material&#8221;, and the third is &#8220;a unit of time&#8221;,  What words do I have in mind?</p></blockquote>
<p>It&#8217;s not difficult to think of three words that fit the descriptions, but it is unlikely you&#8217;ll pick the three I had in mind.  Now try a second task:</p>
<blockquote cite="http://www.amazon.com/gp/product/0465067107/ref=pd_cp_b_title/102-1452992-3960136"><p>This time I&#8217;m looking for rhyming words.  I&#8217;m thinking of three words: one rhymes with &#8220;post&#8221;, the second with &#8220;eel&#8221; and the third with &#8220;ear&#8221;.  What words am I thinking of?</p></blockquote>
<p>Again, you can think of three words which match the descriptions easily, but which ones did I have in mind, last but not least:</p>
<blockquote cite="http://www.amazon.com/gp/product/0465067107/ref=pd_cp_b_title/102-1452992-3960136"><p>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 &#8220;post&#8221;?  What word is the name of a building material and rhymes with &#8220;eel&#8221;?  And what word is a unit of time and rhymes with &#8220;ear&#8221;?</p></blockquote>
<p>Now the task is easy, the combination of just two constraints reduces the selection until there are only three words which fit&#8230; &#8220;ghost&#8221;, &#8220;steel&#8221; and &#8220;year&#8221;!</p>
<p>This was taken from a book I&#8217;m rather enjoying called &#8220;The Design of Everyday Things&#8221; by <a href="http://en.wikipedia.org/wiki/Donald_Norman" title="The Wikipedia article on the author Donald A. Norman">Donald A. Norman</a> 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!)</p>
<p>(and <strong>no</strong> this isn&#8217;t one of those horrible <a href="http://en.wikipedia.org/wiki/Pay_Per_Post" title="A link to a Wikipedia article describing the principle (or lack there of) pay per post">pay per post</a> things, if you want to read it try a library <img src='http://craigloftus.net/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )</p>
]]></content:encoded>
			<wfw:commentRss>http://craigloftus.net/blog/2006/11/03/power-of-constraints/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

