def __init__(self, partNumber): distpart.DistItem.__init__(self, partNumber) self.avail = 0 self.min_order = 0 self.price_for = 1 self.multi = 1 self.prices = [] self.cost = [] self.qty_range = 0 page = grab_url_cached('https://xgoat.com/p/digikey/' + str(partNumber)) soup = BeautifulSoup(page) # Extract availability qa_heading = soup.find(text='Quantity Available') if qa_heading == None: raise distpart.NonExistentPart(self.part_number) qa = qa_heading.findNext('td').contents[0].string if qa != None: self.avail = int(qa.replace(',', '')) else: self.avail = 0 # Extract order multiple sp_heading = soup.find(text='Standard Package') self.multi = int( sp_heading.parent.findNext('td').contents[0].replace(',', '')) # Extract pricing # Get a list of the table rows, the first one is the heading row price_table_trs = soup.find( text='Price Break').parent.parent.parent.findAll('tr') for row in price_table_trs: next_row = row.nextSibling.nextSibling # Skip first row as it contains headings, it does however give access # to the minimum quantity value on the next row if row.find('th') != None: self.min_order = int(next_row.contents[0].string.replace( ',', '')) continue if next_row != None: # Get top range of quantity from the next row qty = int(next_row.contents[0].string.replace(',', '')) - 1 else: # For the last row just use its own quantity, there is no next row qty = int(row.contents[0].string.replace(',', '')) cost = Decimal(row.contents[1].string) self.prices.append((qty, cost))
def __init__(self, partNumber): distpart.DistItem.__init__(self, partNumber) self.avail = 0 self.min_order = 0 self.price_for = 1 self.multi = 1 self.prices = [] self.cost = [] self.qty_range = 0 page = grab_url_cached('https://xgoat.com/p/digikey/'+str(partNumber)) soup = BeautifulSoup(page) # Extract availability qa_heading = soup.find(text='Quantity Available') if qa_heading == None: raise distpart.NonExistentPart( self.part_number ) qa = qa_heading.findNext('td').contents[0].string if qa != None: self.avail = int(qa.replace(',','')) else: self.avail = 0 # Extract order multiple sp_heading = soup.find(text='Standard Package') self.multi = int(sp_heading.parent.findNext('td').contents[0].replace(',','')) # Extract pricing # Get a list of the table rows, the first one is the heading row price_table_trs = soup.find(text='Price Break').parent.parent.parent.findAll('tr') for row in price_table_trs: next_row = row.nextSibling.nextSibling # Skip first row as it contains headings, it does however give access # to the minimum quantity value on the next row if row.find('th') != None: self.min_order = int(next_row.contents[0].string.replace(',','')) continue; if next_row != None: # Get top range of quantity from the next row qty = int(next_row.contents[0].string.replace(',',''))-1 else: # For the last row just use its own quantity, there is no next row qty = int(row.contents[0].string.replace(',','')) cost = Decimal(row.contents[1].string) self.prices.append( (qty, cost) )
def _getinfo(self): "Load information from the distributor" page = grab_url_cached( 'https://xgoat.com/p/rs/{0}'.format(self.part_number) ) soup = BeautifulSoup(page) if not self._check_exists(soup): raise distpart.NonExistentPart # Check that the page we've been returned is for the requested part: if not self._soup_check_part(soup): raise distpart.NonExistentPart self._get_availability(soup) # Only get pricing if it's not discontinued if self.avail: self._get_pricing(soup)
def _get_data(self): page = grab_url_cached( 'https://xgoat.com/p/farnell/{0}'.format(self.part_number) ) soup = BeautifulSoup(page) # Check that it exists if not self._check_exists(soup): raise distpart.NonExistentPart( self.part_number ) # Check that the part we've retrieved is the requested part: if not self._soup_check_part(soup): raise distpart.NonExistentPart( self.part_number ) self._get_availability(soup) if self.avail != None and not isinstance(self.avail, bool): self._get_pricing(soup) self._get_constraints(soup)
def _getinfo(self): "Load information from the distributor" page = grab_url_cached('https://xgoat.com/p/rs/{0}'.format( self.part_number)) soup = BeautifulSoup(page) if not self._check_exists(soup): raise distpart.NonExistentPart # Check that the page we've been returned is for the requested part: if not self._soup_check_part(soup): raise distpart.NonExistentPart self._get_availability(soup) # Only get pricing if it's not discontinued if self.avail: self._get_pricing(soup)
def _get_data(self): page = grab_url_cached('https://xgoat.com/p/farnell/{0}'.format( self.part_number)) soup = BeautifulSoup(page) # Check that it exists if not self._check_exists(soup): raise distpart.NonExistentPart(self.part_number) # Check that the part we've retrieved is the requested part: if not self._soup_check_part(soup): raise distpart.NonExistentPart(self.part_number) self._get_availability(soup) if self.avail != None and not isinstance(self.avail, bool): self._get_pricing(soup) self._get_constraints(soup)
def __getData(self, partNumber): page = grab_url_cached( 'https://xgoat.com/p/farnell/'+str(partNumber) ) start = string.find(page, '<div class="availability">') if start == -1: raise Exception( """Part number "%s" doesn't exist""" % str(partNumber) ) info = page[start:] end = string.find(info, '<div class="price">') availInfo = info[:end] start = string.find(page, '<div class="price">') if start == -1: raise Exception( """Part number "%s" doesn't exist""" % str(partNumber) ) info = page[start:] end = string.find(info, '</div>') priceInfo = info[:end] return availInfo+priceInfo
def __getData(self, partNumber): page = grab_url_cached( 'https://xgoat.com/p/rs/'+str(partNumber) ) start = string.find(page, 'id="stockY"') if start != -1: self.avail = 'In stock' else: start = string.find(page, 'Temporarily out of stock -') info = page[start:] end = string.find(info, '\n') self.avail = self._parse_availability(info[:end]) start = string.find(page, '<table id="productdatatable"') if start == -1: raise Exception( """Part number "%s" doesn't exist""" % str(partNumber) ) info = page[start:] end = string.find(info, '</table>') priceInfo = info[:end] return priceInfo
def __getData(self, partNumber): page = grab_url_cached('https://xgoat.com/p/farnell/' + str(partNumber)) start = string.find(page, '<div class="availability">') if start == -1: raise Exception("""Part number "%s" doesn't exist""" % str(partNumber)) info = page[start:] end = string.find(info, '<div class="price">') availInfo = info[:end] start = string.find(page, '<div class="price">') if start == -1: raise Exception("""Part number "%s" doesn't exist""" % str(partNumber)) info = page[start:] end = string.find(info, '</div>') priceInfo = info[:end] return availInfo + priceInfo