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.
Posted in Books, Distractions, Scripts | 2 Comments »
The following is a copy of the letter I sent to my MP regarding the Digital Economy Bill.
Dear Don Foster,
I have read of your position on the Digital Economy Bill and I am mostly pleased by it; we all like carrots over sticks.
I am writing to first add another voice to the mêlée pressuring MPs to ensure any self serving items introduced at the behest of lobbies are removed and that Labour’s draconian approach is resisted. Aside from any discussion on the societal cost of copyright, an act that press-gangs one group of companies into acting as policemen for another group is a many faced abomination.
Second; to give you the perspective of a PhD student at the University of Bath; one of the stereotyped targets for this bill. I can tell you we would dodge any stick you might try to hit us with. Without meaning to sound arrogant; I and my peers are more familiar with IT than you and yours. We know of and can use technology, to make ourselves anonymous and to encrypt the data we send.
Third, I fully believe the whole system of copyright in this country has lost sight of its original intentions and now solely benefits copyright holders while preventing creative endeavour. Not unsurprisingly, the current argument playing out is framed entirely as a dichotomy, ‘stricter controls’ or ‘what we have now’? But I’m sure an intelligent and interested man such as yourself will already be fully aware of arguments for the drawing-back of copyright. I would be thrilled to see you make your peers just as aware.
On this topic I recommend Jamie Boyle’s book The Public Domain: Enclosing the Commons of the Mind (ISBN:978-0300137408).
Finally, I am extremely disappointed in the behaviour of the Lib. Dem. lords in introducing an amendment such as they did.
Yours sincerely,
Craig Loftus
P.S. I never download music or films; I buy CDs and rent DVDs. I do however enjoy the occasional YouTube clip.
Posted in Letters | No Comments »
I recently got one of these household electricity display devices
things and being the information fiend that I am I’ve started studiously recording how much electricity I use. That lead to the obvious question, How much is normal electricity consumption in the UK
. The Internet did not provide me with reliable and consistent answer to this question, so after not inconsiderable rooting for information, I derived the answer from the most up to date available:
1 860 kWh (per person per year, UK, 2007). I’ll write about how my consumption compares once I have more lovely data to play with.
That is based on data from The Department of Business Innovation and Skills on the UK domestic electricity consumption in 2007 (117 126.2 GWh) and the associated number of domestic meters (26 670.3×103) 1. For the per person figure, the UK 2001 Census provides a persons per household figure of 2.36 2.
- Electricity Consumption Data at Regional and Local Authority Level
- Census 2001 – People and their homes in England and Wales
Posted in Uncategorized | 5 Comments »
My letter to my MP, Don Foster, regarding Clause 152 of the Coroners and Justice Bill.
Dear Don Foster,
I would like to draw your attention to Clause 152 of the Coroners and
Justice Bill. The Bill is currently in the committee phase. I am not
very familiar with reading legislation or interpreting it, but having
read the clause, I would summarise as follows.
The clause amends the Data Protection Act 1998 to allow ministers to
break the act (by sharing personal information) when it is “necessary
to secure a relevant policy” i.e. whenever they like. No restriction is
placed on who the information may be shared with, or for what purposes.
Part B, subsection (2) also allows for the creation of offences through
the issuing of information sharing orders… I don’t know how these
things are normally done, but that just doesn’t sound right.
I fear this is a “get out clause” for those who feel tied by the Data
Protection Act. It also seems to clear barriers to sharing of personal
information between government departments… but further places no
restriction on sharing with the private sector.
Yours sincerely,
Craig Loftus
My letter was sent with the aid of WriteToThem.com.
Posted in Letters | No Comments »
For the last few days my eyes have been feeling strained and I’ve had a constant low-level headache. I’m usually pretty good at knowing what is wrong, and I was sure that my prescription was off.
I wasn’t wrong. Although the optometrist said that the relatively sudden onset of headaches was probably the result of working too hard (most of my few readers are probably laughing now).
This table compares today’s prescription with my last one.
|
| 2007-06-11 |
2009-02-19 |
| Right |
Left |
Right |
Left |
| SPH |
-4.75 |
-4.50 |
-5.25 |
-5.00 |
| CYL |
-0.25 |
-0.25 |
-0.25 |
-0.25 |
| AXIS |
90 |
85 |
85 |
95 |
Basically, I am more myoptic (short sighted, represented by SPH), but my astigmatism (none spherical-ness of the eye, CYL) is the same. Oddly, the ways my eyes are pointing (Axis) has reversed… either that or someone wrote them down the wrong way around!
To cut a boring story off quickly, I ended up shelling out £309 for a new pair of frames and lenses! My current frames have last for about 5 years (with 3 prescription changes), so hopefully it will be money well spent.
Posted in Personal | No Comments »