Putting away my work for ry...hope it's ok

pull/1/head
Raymond Yee 2012-02-13 11:28:21 -08:00
parent e043086775
commit c04aacec4a
2 changed files with 17 additions and 4 deletions

View File

@ -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)

View File

@ -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]