Beispiel #1
0
    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 is None:
            raise distpart.NonExistentPart(self.part_number)

        qa = qa_heading.findNext('td').text
        qa = re.search("[1-9](?:\d{0,2})(?:,\d{3})*", qa)
        if qa is not None:
            qa = qa.group(0)
            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 = soup.find(text='Price Break').parent.parent.parent
        price_table_trs = price_table.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') is not None:
                self.min_order = int(next_row.contents[0].string.replace(',',
                                                                         ''))
                continue
            if next_row is not 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))
Beispiel #2
0
    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 is None:
            raise distpart.NonExistentPart(self.part_number)

        qa = qa_heading.findNext('td').text
        qa = re.search("[1-9](?:\d{0,2})(?:,\d{3})*", qa)
        if qa is not None:
            qa = qa.group(0)
            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 = soup.find(text='Price Break').parent.parent.parent
        price_table_trs = price_table.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') is not None:
                self.min_order = int(next_row.contents[0].string.replace(
                    ',', ''))
                continue
            if next_row is not 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))
Beispiel #3
0
    def _getinfo(self):
        """Load information from the distributor."""
        rs_url = 'http://uk.rs-online.com/web/p/products/{part_number}/'
        page = grab_url_cached(rs_url.format(part_number=self.part_number))

        soup = BeautifulSoup(page)

        if not self._check_exists(soup):
            raise distpart.NonExistentPart(self.part_number)

        # 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)
Beispiel #4
0
    def _get_data(self):
        farnell_url = 'https://xgoat.com/p/farnell/{0}'
        page = grab_url_cached(farnell_url.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 is not None and not isinstance(self.avail, bool):
            self._get_pricing(soup)
            self._get_constraints(soup)
Beispiel #5
0
    def _getinfo(self):
        """Load information from the distributor."""
        mouser_url = 'https://xgoat.com/p/mouser/{part_number}'
        page = grab_url_cached(mouser_url.format(part_number=self.part_number))

        soup = BeautifulSoup(page)

        if not self._check_exists(soup):
            raise distpart.NonExistentPart(self.part_number)

        # Check that the page we've been returned is for the requested part:
        if not self._soup_check_part(soup):
            raise distpart.NonExistentPart(self.part_number)

        self._get_availability(soup)

        # Only get pricing if it's not discontinued
        if self.avail is not None and not isinstance(self.avail, bool):
            self._get_pricing(soup)
            self._get_constraints(soup)