diff --git a/core/bookloader.py b/core/bookloader.py index 7c64fcea..4f603fcd 100755 --- a/core/bookloader.py +++ b/core/bookloader.py @@ -223,11 +223,15 @@ def add_related(isbn): """ # make sure the seed edition is there logger.info("adding related editions for %s", isbn) + + new_editions = [] + edition = add_by_isbn(isbn) + if edition is None: + return new_editions # this is the work everything will hang off work = edition.work - new_editions = [] other_editions = {} for other_isbn in thingisbn(isbn): # 979's come back as 13 diff --git a/core/librarything.py b/core/librarything.py index dfd2c6af..e18d52e0 100644 --- a/core/librarything.py +++ b/core/librarything.py @@ -131,6 +131,9 @@ class LibraryThing(object): # isbn try: book_data["isbn"] = cols[4].xpath('.//span')[0].text + # check for   + if book_data["isbn"] == u'\xA0': + book_data["isbn"] = None except Exception, e: book_data["isbn"] = None @@ -143,6 +146,8 @@ class LibraryThing(object): # we can vary viewstyle to get different info IMPLEMENTED_STYLES = [1,5] + COLLECTION = 2 # set to get All Collections + if view_style not in IMPLEMENTED_STYLES: raise NotImplementedError() style_parser = getattr(self,"viewstyle_%s" % view_style) @@ -151,8 +156,8 @@ class LibraryThing(object): cookies = None while next_page: - url = "http://www.librarything.com/catalog_bottom.php?view=%s&viewstyle=%d&offset=%d" % (self.username, - view_style, offset) + url = "http://www.librarything.com/catalog_bottom.php?view=%s&viewstyle=%d&collection=%d&offset=%d" % (self.username, + view_style, COLLECTION, offset) logger.info("url: %s", url) if cookies is None: r = requests.get(url) @@ -163,6 +168,7 @@ class LibraryThing(object): raise LibraryThingException("Error accessing %s: %s" % (url, e)) logger.info("Error accessing %s: %s", url, e) etree = html.fromstring(r.content) + #logger.info("r.content %s", r.content) cookies = r.cookies # retain the cookies # look for a page bar diff --git a/test/booktests.py b/test/booktests.py new file mode 100644 index 00000000..0d4c3799 --- /dev/null +++ b/test/booktests.py @@ -0,0 +1,28 @@ +from regluit.core import librarything, bookloader +import itertools +import django + +def ry_lt_books(): + """return parsing of rdhyee's LibraryThing collection""" + lt = librarything.LibraryThing('rdhyee') + books = lt.parse_user_catalog(view_style=5) + return books + +def editions_for_lt(books): + """return the Editions that correspond to the list of LibraryThing books""" + editions = [bookloader.add_by_isbn(b["isbn"]) for b in books] + return editions + +def ry_lt_not_loaded(): + """Calculate which of the books on rdhyee's librarything list don't yield Editions""" + books = list(ry_lt_books()) + editions = editions_for_lt(books) + not_loaded_books = [b for (b, ed) in itertools.izip(books, editions) if ed is None] + return not_loaded_books + +def ry_wish_list_equal_loadable_lt_books(): + """returnwhether the set of works in the user's wishlist is the same as the works in a user's loadable editions from LT""" + editions = editions_for_lt(ry_lt_books()) + # assume only one user -- and that we have run a LT book loading process for that user + ry = django.contrib.auth.models.User.objects.all()[0] + return set([ed.work for ed in filter(None, editions)]) == set(ry.wishlist.works.all()) \ No newline at end of file