def perform(self, query=None): amazon = Vendor.query.filter( db.or_(Vendor.url.ilike('%amazon.com%'), Vendor.name.ilike('amazon'), Vendor.name.ilike('amazon.com'))).one() # Modify the filter to exclude listings from Amazon listings = filter_with_json( Listing.query, query).filter(Listing.vendor_id != amazon.id) for listing in listings: if listing.brand and listing.model: query_str = f'{listing.brand} {listing.model}' elif listing.title: query_str = listing.title else: raise ValueError( 'Listing does not contain enough information to match.') self.context.child( mws.ListMatchingProducts.message(query=query_str), ProcessListings.message(), data={ 'vendor_id': listing.vendor_id }).send()
def post(self, type_, query): obj_type = getattr(models, type_) query = core.filter_with_json(obj_type.query, query) query.delete() app.db.session.commit() return {'status': 'ok'}
def perform(self, query=None): """Delegate the update operation to the vendor extensions.""" vendors = filter_with_json(Vendor.query, {'listings': query}) for vendor in vendors: try: message = vendor.extension.message('UpdateListings') except (ValueError, AttributeError): continue self.context.bind(message)
def perform(self, query=None): katom = Vendor.query.filter( db.or_(Vendor.url.ilike('%katom.com%'), Vendor.name.ilike('katom%'))).one() query.update(vendor_id=katom.id) listings = filter_with_json(Listing.query, query) urls = [ listing.detail_url or f'http://www.katom.com/{listing.sku}.html' for listing in listings ] self.context.send(Crawl.message(urls=urls))
def post(self, type_, query, data): obj_type = getattr(models, type_) loaded = obj_type.__schema__().load(data, partial=True) if loaded.errors: return {'errors': loaded.errors} query = core.filter_with_json(obj_type.query, query) for obj in query.all(): obj.update(loaded.data) app.db.session.commit() return {'status': 'ok'}
def post(self, type_, query, view, schema): obj_type = getattr(models, type_) query = core.filter_with_json(obj_type.query, query) page = query.paginate(page=view['context']['_page'], per_page=view['context']['_per_page']) items = [m.to_json(view, _schema=schema) for m in page.items] return { 'total': page.total, 'page': page.page, 'pages': page.pages, 'per_page': page.per_page, 'items': items, 'schema': obj_type.json_schema(view) }
def perform(self, query=None): amazon = Vendor.query.filter( db.or_(Vendor.url.ilike('%amazon.com%'), Vendor.name.ilike('amazon'), Vendor.name.ilike('amazon.com'))).one() query.update(vendor_id=amazon.id) listings = filter_with_json(Listing.query, query) for listing in listings: self.context.child(mws.GetCompetitivePricingForASIN.message(), pa.ItemLookup.message(), mws.GetMyFeesEstimate.message(), ImportListing.message(), title=f'Update SKU #{listing.sku}', data={ 'listing': { 'sku': listing.sku } }).send()