def get_authors_from_amazon(auth_missing=None): if not auth_missing: auth_missing = [] for t in auth_missing: t1 = Title.get(t) try: amazonIter = ItemLookup(t1.isbn, ResponseGroup="ItemAttributes") amazonResults = next(amazonIter) if isinstance(getattr(amazonResults, "Author", False), type("")): auth = [getattr(amazonResuts, "Author", None)] else: auth = getattr(amazonResults, "Author", []) print(auth) if isinstance(getattr(amazonResults, "Creator", False), type("")): auth.extend([getattr(amazonResuts, "Creator", None)]) else: auth.extend(getattr(amazonResults, "Creator", [])) au_rec = "" for au in auth: try: Author(authorName=au) except Exception: pass au_rec = Author.selectBy(authorName=au)[0] print(au_rec) t1.addAuthor(au_rec) print((t1.author)) except Exception as e: print(e)
def OnAdd(self,event): a = Author.selectBy(author_name = self.author_name.GetValue().encode("ascii", "backslashreplace")) if len(list(a)) != 0: a = wxMessageDialog(self, "This author is already in the list", "Error", wxOK + wxICON_ERROR) a.ShowModal() else: a = Author(author_name = self.author_name.GetValue().encode("ascii", "backslashreplace")) # This call deleteallitems on the author list. This is bad if there is a large amount of # authors, we should simply add the new one. self.loadAllAuthors()
def addToInventory(self, title="", status="STOCK", authors=[], publisher="", price="", isbn="", categories=[], distributor="", owner="", notes="", quantity=1, known_title=False, kind_name="", extra_prices={}): if not (known_title): #add a title the_kinds = list(Kind.select(Kind.q.kindName == kind_name)) kind_id = None if the_kinds: kind_id = the_kinds[0].id known_title = Title(isbn=isbn, booktitle=title.encode("ascii", "backslashreplace"), publisher=publisher.encode( "ascii", "backslashreplace"), tag=" ", kindID=kind_id) for rawAuthor in authors: author = rawAuthor.encode("ascii", "backslashreplace") theAuthors = Author.selectBy(author_name=author) theAuthorsList = list(theAuthors) if len(theAuthorsList) == 1: known_title.addAuthor(theAuthorsList[0]) elif len(theAuthorsList) == 0: a = Author(author_name=author) known_title.addAuthor(a) else: # We should SQLDataCoherenceLost here print "mmm... looks like you have multiple author of the sama name in your database..." for category in categories: Category(categoryName=category.encode("ascii", "backslashreplace"), title=known_title) for i in range(int(quantity)): print distributor.encode('ascii', "backslashreplace") wholesale = 0 try: wholesale = extra_prices['wholesale'] except: pass b = Book(title=known_title, status=status.encode("ascii", "backslashreplace"), distributor=distributor.encode('ascii', "backslashreplace"), listprice=price, owner=owner.encode("ascii", "backslashreplace"), notes=notes.encode("ascii", "backslashreplace"), consignmentStatus="", wholesale=wholesale) b.extracolumns() for mp in extra_prices.keys(): setattr(b, string.replace(mp, " ", ""), extra_prices[mp])
def addToInventory( title="", status="STOCK", authors=None, publisher="", listprice="", ourprice="", isbn="", orig_isbn="", categories=[], distributor="", location="", location_id="", large_url="", med_url="", small_url="", owner="", notes="", quantity=1, known_title=False, types="", kind_name="", kind=default_kind, extra_prices={}, tag="", labels_per_copy=1, printlabel=False, special_orders=0, ): print("GOT to addToInventory", file=sys.stderr) if not authors: authors = [] if known_title: print("known_title ", known_title, file=sys.stderr) if not known_title.booktitle: known_title.booktitle = title if not known_title.publisher: known_title.publisher = publisher if not known_title.type: known_title.type = types elif not (known_title): print("unknown title", file=sys.stderr) # add a title the_kinds = list(Kind.select(Kind.q.kindName == kind)) kind_id = None if the_kinds: kind_id = the_kinds[0].id print("kind id is", kind_id, file=sys.stderr) # print>>sys.stderr, title title = title publisher = publisher # print>>sys.stderr, title, publisher known_title = Title( isbn=isbn, origIsbn=orig_isbn, booktitle=title, publisher=publisher, tag=" ", type=types, kindID=kind_id, ) print(known_title, file=sys.stderr) im = Images( titleID=known_title.id, largeUrl=large_url, medUrl=med_url, smallUrl=small_url, ) print(im, file=sys.stderr) for rawAuthor in authors: author = rawAuthor theAuthors = Author.selectBy(authorName=author) theAuthorsList = list(theAuthors) if len(theAuthorsList) == 1: known_title.addAuthor(theAuthorsList[0]) elif len(theAuthorsList) == 0: a = Author(authorName=author) known_title.addAuthor(a) else: # We should SQLDataCoherenceLost here print( "mmm... looks like you have multiple author of the sama name in your database...", file=sys.stderr, ) for category in categories: Category(categoryName=category, title=known_title) # the_locations=list(Location.select(Location.q.locationName==location)) # location_id=1 # if the_locations: # location_id = the_locations[0].id if not ourprice: ourprice = listprice print("about to enter book loop", file=sys.stderr) print("location is", location, file=sys.stderr) print("location_id is", location_id, file=sys.stderr) for i in range(int(quantity)): print("book loop", file=sys.stderr) b = Book( title=known_title, status=status, distributor=distributor, listprice=listprice, ourprice=ourprice, location=int(location_id), owner=owner, notes=notes, consignmentStatus="", )