def SearchByKeyword(repView, keywords=None, countryCode=None, category=None): """ Performs an amazon search by keyword and creates an AmazonCollection containing AmazonItem's for each product found that matches the search criteria (only retrieves the first 10 products). If an AmazonCollection already exists for the search criteria the method creates AmazonItem's for new products and adds them to the existing collection. The method can be used programatically or via user input. If no keywords, countryCode, and category variables are passed in, an Amazon Search By Keyword dialog is displayed for the user to choose the keywords, countryCode, and category. The method contacts the Amazon site specified by the countryCode and retrieves the products that match the search criteria. @type repView: A Repository.view @param repView: The repository view in which to create the AmazonItems' and AmazonCollection @type keywords: unicode @param keywords: The keywords to search on. If the value is None a dialog is displayed for the user to enter the information. @type countryCode: unicode @param countryCode: The countryCode of the amazon site to contact. If the value is None a dialog is displayed for the user to enter the information. @type category: unicode @param category: The category to search in. If the value is None a dialog is displayed for the user to enter the information. @rtype: AmazonCollection or None @return: An AmazonCollection containing AmazonItem's for each product or None if no products found or an error occurs. """ if keywords is None or countryCode is None or category is None: keywords, countryCode, category = AmazonDialog.promptKeywords() if _isEmpty(keywords): """ The user did not enter any text to search on or hit the cancel button """ return None while True: try: bags = amazon.searchByKeyword(keywords, locale=countryCode, product_line=category) return _AddToCollection(repView, keywords, countryCode, bags) except amazon.NoLicenseKey: if AmazonDialog.promptLicense(): continue return None except (amazon.AmazonError, AttributeError), e: dt = {'keywords': keywords} _showError(_(u"No Amazon products were found for keywords '%(keywords)s'") % dt) return None
def SearchWishListByEmail(repView, emailAddr=None, countryCode=None): """ Retrieves an amazon wishlist by email address and creates an AmazonCollection containing AmazonItem's for each product in the wishlist (only retrieves first 10 products found). If an AmazonCollection already exists for the search criteria the method creates AmazonItem's for new products and adds them to the existing collection. The method can be used programatically or via user input. If no emailAddr and countryCode variables are passed in, an Amazon WishList By Email dialog is displayed for the user to input the emailAddr and countryCode. The method contacts the Amazon site specified by the countryCode and retrieves the products for the wishlist. @type repView: A Repository.view @param repView: The repository view in which to create the AmazonItems' and AmazonCollection @type emailAddr: unicode @param emailAddr: The email address for the user wishlist @type countryCode: unicode @param countryCode: The countryCode of the amazon site to contact. If the value is None a dialog is displayed for the user to enter the information. @rtype: AmazonCollection or None @return: An AmazonCollection containing AmazonItem's for each product or None if no products found or an error occurs. """ if emailAddr is None or countryCode is None: emailAddr, countryCode = AmazonDialog.promptEmail() if _isEmpty(emailAddr): return None while True: try: customerName, bags = \ amazon.searchWishListByEmail(emailAddr, locale=countryCode) return _AddToCollection(repView, customerName, countryCode, bags) except amazon.NoLicenseKey: if AmazonDialog.promptLicense(): continue return None except (amazon.AmazonError, AttributeError), e: dt = {'emailAddress': emailAddr} _showError(_(u"No Amazon Wishlist was found for email address '%(emailAddress)s'") % dt) return None