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 get_authors_from_amazon(auth_missing=[]): for t in auth_missing: t1=Title.get(t) try: amazonIter=ItemLookup(t1.isbn, ResponseGroup="ItemAttributes") amazonResults=amazonIter.next() if type( getattr(amazonResults, 'Author', False)) == type(u''): auth= [ getattr(amazonResuts, 'Author', None) ] else: auth=getattr( amazonResults, 'Author', []) print auth if type( getattr(amazonResults,'Creator', False)) == type(u''): 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 OnSave(self,event): # Here we need to translate the list of author that are # currently selected to a list of author_id if self.currentAuthorList.GetItemCount() == 0: a = wxMessageDialog(self, "Can't save an empty author list, create an anonymous author and set him at least as the author", "Error", wxOK + wxICON_ERROR) a.ShowModal() else: list_of_author = [] item = -1 # For all the authors in the list of authors for i in range(0,self.allAuthorList.GetSelectedItemCount()): item = self.allAuthorList.GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); # Get the name of the author his_name = self.allAuthorList.GetItemText(item).encode("ascii", "backslashreplace") # and try to find the name in the database. if there is # multiple, we just don't care #try: a = Author.selectBy(author_name = his_name) b = list(a) print b print b[0] list_of_author.append(b[0].id) #except: # print his_name # print "Something real weird happened" print list_of_author self.parent.list_of_author = list_of_author self.execWhenSelected(list_of_author) self.parent.OnCancel(event)
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="",listprice="",ourprice='',isbn="",categories=[],distributor="",location="",owner="",notes="",quantity=1,known_title=False,types='',kind_name="",kind=default_kind, extra_prices={}, tag='', num_copies=0, printlabel=False): print "GOT to addToInventory" if not(known_title): print "unknown title" #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 #print title title=title publisher=publisher #print title, publisher known_title=Title(isbn=isbn, booktitle=title, publisher=publisher,tag=" ",type=types, kindID=kind_id) print known_title for rawAuthor in authors: author = rawAuthor.encode("utf8", "backslashreplace") 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..." for category in categories: Category(categoryName=category.encode("utf8", "backslashreplace"),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 for i in range(int(quantity)): #print "book loop" b=Book(title=known_title,status=status.encode("utf8", "backslashreplace"), distributor=distributor.encode('ascii', "backslashreplace"),listprice=listprice, ourprice=ourprice, location=location_id,owner=owner.encode("utf8", "backslashreplace"),notes=notes.encode("utf8", "backslashreplace"),consignmentStatus="")
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(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="", )