def test_oclc_22239204(self): # Book found, but no data oclc = 22239204 info = get_by_oclc(oclc) self.assertIn(('oclc', str(oclc)), info['identifiers']) self.assertNotIn('authors', info) self.assertNotIn('title', info)
def getBookData(urlOrNum): if urlOrNum.isdigit(): oclc = urlOrNum thisdict = worldcat_api.get_by_oclc(oclc) if thisdict is None: error('The OCLC number entered was not found.') return thisdict book_url = urlOrNum #print "url:", book_url, "<br />" if not re.search('books.google.', book_url, re.I) and not re.search('\?id=', book_url, re.I): error('Not a Google Books URL.') return urlsep = re.search('\?([^#]*)', book_url) if not urlsep: error('Bad URL.') return book_url_qs = urlsep.group(1) #print "url_qs:", book_url_qs, "<br />" book_url_qs_fields = cgi.parse_qs(book_url_qs) #print "book_url_qs_fields:", book_url_qs_fields, "<br />" if "id" not in book_url_qs_fields: error('Bad URL. It has to be for a specific book, not a search result page') return book_id = book_url_qs_fields["id"][0] #print "book_id:", book_id, "<br />" page = '' page_string = '' if 'pg' in book_url_qs_fields: page_string = book_url_qs_fields['pg'][0] match = re.search('\D*(\d+)', page_string) if match: page = match.group(1) + u"\u2013".encode("utf-8") new_url = 'http://books.google.com/books?id=' + urllib.quote_plus(book_id) if page_string: new_url += '&pg=' + urllib.quote_plus(page_string) client = gdata.books.service.BookService() gdata.alt.appengine.run_on_appengine(client) try: thisbook = client.get_by_google_id(book_id) # '8cp-Z_G42g4C' thisdict = thisbook.to_dict() thisdict['page'] = page thisdict['new_url'] = new_url return thisdict except Exception, err: print >> sys.stderr, 'ERROR: %s\n' % str(err) error('No information available for this URL.') return
def test_oclc(self): oclc = '550538756' info = get_by_oclc(oclc) self.assertEquals(info['title'], "On hobos and homelessness") self.assertIn('Nels Anderson', info['authors'][0]) self.assertIn('1998', info['date']) self.assertIn('Chicago Press', info['publishers'][0]) identifiers = info['identifiers'] self.assertIn(('oclc', oclc), identifiers) self.assertIn(('isbn', '9780226019666'), identifiers)
def test_igma(self): oclc = '608542024' info = get_by_oclc(oclc) self.assertEquals(info['title'], "It probably won't kill you ... : twisted humor for your kitchen") self.assertEquals('Iyan Igma', info['authors'][0]) self.assertIn('2009', info['date']) self.assertIn('CreateSpace', info['publishers'][0]) identifiers = info['identifiers'] self.assertIn(('oclc', oclc), identifiers) self.assertIn(('isbn', '9781441476562'), identifiers)
def test_bad_oclc(self): #Bad OCLC (actual an ISBN) oclc = '1441476563' info = get_by_oclc(oclc) self.assertIsNone(info)
def test_oclc_2340417(self): # Returns an HTTP error oclc = 2340417 info = get_by_oclc(oclc) self.assertIsNone(info)
def test_oclc_35883297(self): #'author': 'ed. by Kenneth T. MacKay' info = get_by_oclc(35883297) self.assertEquals(info['authors'], ['Kenneth T. MacKay'])
def test_oclc_41271560(self): #'author': u'[Michael Wielsch, Jens Prahm] ; [trad. Liger Fran\xe7ois, Wolf Pierre M., Springinsfeld Serge].' info = get_by_oclc(41271560) self.assertEquals(info['authors'], ['Michael Wielsch', 'Jens Prahm'])