From c04aacec4a5cf40efa782b3d998205995a9998a6 Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Mon, 13 Feb 2012 11:28:21 -0800 Subject: [PATCH] Putting away my work for ry...hope it's ok --- experimental/bookdata.py | 17 +++++++++++++++-- test/load_test.py | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/experimental/bookdata.py b/experimental/bookdata.py index e72c836d..5071a62a 100644 --- a/experimental/bookdata.py +++ b/experimental/bookdata.py @@ -45,7 +45,7 @@ SURFACING_WORK_OLID = 'OL675829W' SURFACING_EDITION_OLID = 'OL8075248M' SURFACING_ISBN = '9780446311076' -USER_AGENT = "rdhyee-test" +USER_AGENT = "rdhyee@gluejar.com" # http://stackoverflow.com/questions/2348317/how-to-write-a-pager-for-python-iterators/2350904#2350904 def grouper(iterable, page_size): @@ -84,12 +84,25 @@ def thingisbn(isbn): """given an ISBN return a list of related edition ISBNs, according to Library Thing. (takes isbn_10 or isbn_13, returns isbn_10, except for 979 isbns, which come back as isbn_13') """ - logger.debug("looking up %s at ThingISBN" , isbn) + logger.info("looking up %s at ThingISBN" , isbn) url = "http://www.librarything.com/api/thingISBN/%s" % isbn xml = requests.get(url, headers={"User-Agent": USER_AGENT}).content doc = ElementTree.fromstring(xml) return [e.text for e in doc.findall('isbn')] +def lt_whatwork(isbn=None, title=None, author=None): + """ + "What work?" takes an ISBN and/or a title-author and returns the LibraryThing work number. + http://www.librarything.com/blogs/thingology/2009/03/new-api-what-work/ + """ + logger.info("looking up at lt_whatwork (isbn, title, author): %s %s %s" ,isbn, title, author) + url = "http://www.librarything.com/api/whatwork.php?" + url = "http://www.librarything.com/api/thingISBN/%s" % isbn + xml = requests.get(url, headers={"User-Agent": USER_AGENT}).content + doc = ElementTree.fromstring(xml) + return [e.text for e in doc.findall('isbn')] + + def hathi_bib(id, id_type='isbn', detail_level='brief'): url = "http://catalog.hathitrust.org/api/volumes/brief/%s/%s.json" % (id_type, id) r = requests.get(url) diff --git a/test/load_test.py b/test/load_test.py index 395e2c53..9fa27d91 100644 --- a/test/load_test.py +++ b/test/load_test.py @@ -20,13 +20,13 @@ def get_with_time(url, label=None): if __name__ == '__main__': n_calls = 100 - n_workers = 25 + n_workers = 15 pool = multiprocessing.Pool(n_workers) url = "http://unglue.it/lists/popular" results = [pool.apply_async(get_with_time, (url,k)) for k in xrange(n_calls)] - print [result.get()[1] for result in results] + print [result.get(999999999)[1] for result in results]