def retrieve(self,number): isbn=number if len(number)==13: isbn=upc2isbn(number) books = Book.select(AND(Book.q.titleID==Title.q.id,Title.q.isbn==isbn,Book.q.status=="STOCK") ) print books if len(list(books))==1: theBook = books[0] if theBook: print theBook self.setBook(theBook) desc=theBook.title.booktitle self.setDescription("%s" % desc) self.source=theBook.title.kind.kindName self.setPrice(theBook.listprice) self.setDistributor(theBook.distributor) return 1 else: if len(list(books))>1: from popups.browseinventory import BrowseInventoryPopup self.browser=BrowseInventoryPopup(self.parent,{"isbn":isbn,"status":"STOCK"}) self.browser.CenterOnScreen() self.browser.ShowModal() return -1 else: return 0
def OnTextEnter(self, event): id = self.number.GetValue() if len(id) == 13 or len(id) == 18: id = upc2isbn(id) #here you want to set browser.link.open_external=0 in about:config in firefox cmd = "http://localhost:8081/private/reinventory?isbn=%s" % (id) os.spawnlp(os.P_NOWAIT, "/usr/bin/firefox", "/usr/bin/firefox", cmd) status = os.system(cmd) self.number.SetValue("")
def OnTextEnter(self,event): id=self.number.GetValue() if len(id)==13 or len(id)==18: id=upc2isbn(id) #here you want to set browser.link.open_external=0 in about:config in firefox cmd="http://localhost:8081/private/reinventory?isbn=%s" % (id) os.spawnlp(os.P_NOWAIT, "/usr/bin/firefox","/usr/bin/firefox",cmd ) status = os.system(cmd) self.number.SetValue("")
def OnText(self, event): id = self.number.GetValue() if len(id) == 13: id = upc2isbn(id) self.OnTextEnter(event)
def lookup_by_isbn(self, number): isbn = "" if len(number) == 13 or len(number) == 18: isbn = upc2isbn(number) else: isbn = number print "NUMBER was " + number + ",ISBN was " + isbn if len(isbn) > 0: #first we check our database titles = Title.select(Title.q.isbn == isbn) print titles #debug self.known_title = False the_titles = list(titles) if len(the_titles) > 0: self.known_title = the_titles[0] ProductName = the_titles[0].booktitle.decode("unicode_escape") authors = [ x.author_name.decode("unicode_escape") for x in the_titles[0].author ] authors_as_string = string.join(authors, ',') categories = [ x.categoryName.decode("unicode_escape") for x in the_titles[0].categorys ] categories_as_string = string.join(categories, ',') if len(the_titles[0].books) > 0: # ListPrice = the_titles[0].books[0].listprice ListPrice = max([b.listprice for b in the_titles[0].books]) else: ListPrice = 0 Manufacturer = the_titles[0].publisher.decode("unicode_escape") else: #we don't have it yet sleep(1) # so amazon doesn't get huffy ecs.setLicenseKey(amazon_license_key) ecs.setSecretAccessKey( 'hCVGbeXKy2lWQiA2VWV8iWgti6s9CiD5C/wxL0Qf') ecs.setOptions({'AssociateTag': 'someoneelse-21'}) pythonBooks = ecs.ItemLookup(isbn, IdType="ISBN", SearchIndex="Books", ResponseGroup="ItemAttributes") if pythonBooks: result = {} authors = [] categories = [] b = pythonBooks[0] for x in ['Author', 'Creator']: if hasattr(b, x): if type(getattr(b, x)) == type([]): authors.extend(getattr(b, x)) else: authors.append(getattr(b, x)) authors_as_string = string.join(authors, ',') categories_as_string = "" ProductName = "" if hasattr(b, 'Title'): ProductName = b.Title Manufacturer = "" if hasattr(b, 'Manufacturer'): Manufacturer = b.Manufacturer ListPrice = "" if hasattr(b, 'ListPrice'): ListPrice = b.ListPrice.FormattedPrice return { "title": ProductName, "authors": authors, "authors_as_string": authors_as_string, "categories_as_string": categories_as_string, "list_price": ListPrice, "publisher": Manufacturer, "isbn": isbn, "known_title": self.known_title }
def OnText(self,event): id=self.number.GetValue() if len(id) == 13: id=upc2isbn(id) self.OnTextEnter(event)
def lookup_by_isbn(number): isbn = "" number = re.sub("^(['\"])(.*)\\1$", "\\2", number) # print "number is now: ", number if len(number) >= 9: number = re.sub("[-\s]", "", number) # print "number is now: ", number if len(number) == 13 or len(number) == 18: isbn = upc2isbn(number) else: isbn = number # print "NUMBER was " +number+ ",ISBN was "+isbn if len(isbn) > 0: # first we check our database titles = Title.select(Title.q.isbn == isbn) # print titles #debug known_title = False the_titles = list(titles) if len(the_titles) > 0: # print "in titles" known_title = the_titles[0] ProductName = the_titles[0].booktitle.format() authors = [x.authorName.format() for x in the_titles[0].author] or [] authors_as_string = string.join(authors, ",") if len(the_titles[0].categorys) > 0: # print len(the_titles[0].categorys) # print the_titles[0].categorys categories = [x.categoryName.format() for x in the_titles[0].categorys] categories_as_string = string.join(categories, ",") if len(the_titles[0].books) > 0: ListPrice = the_titles[0].books[0].listprice else: ListPrice = 0 Manufacturer = the_titles[0].publisher.format() Format = the_titles[0].type.format() Kind = the_titles[0].kind.kindName else: # we don't have it yet # print "in isbn" sleep(1) # so amazon doesn't get huffy ecs.setLicenseKey(amazon_license_key) ecs.setSecretAccessKey(amazon_secret_key) ecs.setAssociateTag(amazon_associate_tag) # print "about to search", isbn, isbn[0] pythonBooks = ecs.ItemLookup( isbn, IdType="ISBN", SearchIndex="Books", ResponseGroup="ItemAttributes,BrowseNodes" ) # print pythonBooks if pythonBooks: result = {} authors = [] categories = [] b = pythonBooks[0] for x in ["Author", "Creator"]: if hasattr(b, x): if type(getattr(b, x)) == type([]): authors.extend(getattr(b, x)) else: authors.append(getattr(b, x)) authors_as_string = string.join(authors, ",") categories_as_string = "" # a bit more complicated of a tree walk than it needs be. # set up to still have the option of category strings like "history -- us" # switched to sets to quickly remove redundancies. def parseBrowseNodes(bNodes): def parseBrowseNodesInner(item): bn = set() if hasattr(item, "Name"): bn.add(item.Name) if hasattr(item, "Ancestors"): # print "hasansc" for i in item.Ancestors: bn.update(parseBrowseNodesInner(i)) if hasattr(item, "Children"): for i in item.Children: bn.update(parseBrowseNodesInner(i)) # print "bn ", bn if not (hasattr(item, "Ancestors") or hasattr(item, "Children")): if hasattr(item, "Name"): return set([item.Name]) else: return set() return bn nodeslist = [parseBrowseNodesInner(i) for i in bNodes] nodes = set() for n in nodeslist: nodes = nodes.union(n) return nodes categories = parseBrowseNodes(b.BrowseNodes) categories_as_string = string.join(categories, ",") ProductName = "" if hasattr(b, "Title"): ProductName = b.Title Manufacturer = "" if hasattr(b, "Manufacturer"): Manufacturer = b.Manufacturer ListPrice = "" if hasattr(b, "ListPrice"): ListPrice = b.ListPrice.FormattedPrice.replace("$", "") Format = "" if hasattr(b, "Binding"): Format = b.Binding Kind = "books" return { "title": ProductName, "authors": authors, "authors_as_string": authors_as_string, "categories_as_string": categories_as_string, "list_price": ListPrice, "publisher": Manufacturer, "isbn": isbn, "format": Format, "kind": Kind, "known_title": known_title, }
def lookup_by_isbn(self,number): isbn="" if len(number)==13 or len(number)==18: isbn=upc2isbn(number) else: isbn=number print "NUMBER was " +number+ ",ISBN was "+isbn if len(isbn)>0: #first we check our database titles = Title.select(Title.q.isbn==isbn) print titles #debug self.known_title= False the_titles=list(titles) if len(the_titles) > 0: self.known_title= the_titles[0] ProductName = the_titles[0].booktitle.decode("unicode_escape") authors = [x.author_name.decode("unicode_escape") for x in the_titles[0].author] authors_as_string = string.join(authors,',') categories = [x.categoryName.decode("unicode_escape") for x in the_titles[0].categorys] categories_as_string = string.join(categories,',') if len(the_titles[0].books) > 0: # ListPrice = the_titles[0].books[0].listprice ListPrice = max([b.listprice for b in the_titles[0].books]) else: ListPrice = 0 Manufacturer = the_titles[0].publisher.decode("unicode_escape") else: #we don't have it yet sleep(1) # so amazon doesn't get huffy ecs.setLicenseKey(amazon_license_key) ecs.setSecretAccessKey('hCVGbeXKy2lWQiA2VWV8iWgti6s9CiD5C/wxL0Qf') ecs.setOptions({'AssociateTag':'someoneelse-21'}) pythonBooks = ecs.ItemLookup(isbn,IdType="ISBN",SearchIndex="Books",ResponseGroup="ItemAttributes") if pythonBooks: result={} authors=[] categories=[] b=pythonBooks[0] for x in ['Author','Creator']: if hasattr(b,x): if type(getattr(b,x))==type([]): authors.extend(getattr(b,x)) else: authors.append(getattr(b,x)) authors_as_string = string.join(authors,',') categories_as_string ="" ProductName="" if hasattr(b,'Title'): ProductName=b.Title Manufacturer="" if hasattr(b,'Manufacturer'): Manufacturer=b.Manufacturer ListPrice="" if hasattr(b,'ListPrice'): ListPrice=b.ListPrice.FormattedPrice return {"title":ProductName, "authors":authors, "authors_as_string":authors_as_string, "categories_as_string":categories_as_string, "list_price":ListPrice, "publisher":Manufacturer, "isbn":isbn, "known_title": self.known_title}