コード例 #1
0
    async def _setProductThumbUrl(self, soup: BeautifulSoup,
                                  product: Product) -> ProductChanged:
        """
        Search for the following JS code and extract URL:
        <div class="more-views mobilehidden">
           <ul>
            <li>
             <a href="https:// ...
        """
        isProductChanged = False

        try:
            urlThumb = soup.find("div", {"class": "product-img-box"}) \
                .find("div", {"class": "more-views mobilehidden"}) \
                .find_next("a").get("href")

        except AttributeError as e:
            logger.warning("Failed finding product image url. %s. %s", e,
                           product.url)
            self._failCount += 1

        else:
            logger.debug("Found product image url. %s", product.url)
            if not product.urlThumb or product.urlThumb != urlThumb:
                product.urlThumb = urlThumb
                isProductChanged = True  # note that we never switch back to False

        finally:
            return isProductChanged
コード例 #2
0
    async def _setProductThumbUrl(self, soup: BeautifulSoup, product: Product) -> ProductChanged:
        isProductChanged = False

        try:
            urlThumb = soup.find("div", class_="thumbnail-1") \
                .find("div", class_="wrap") \
                .img["src"]

            if not urlThumb: raise AttributeError("No matches in HTML tree.")

        except AttributeError as e:
            logger.warning("Failed finding product image url. %s. %s", e, product.url)
            self._failCount += 1

        else:
            logger.debug("Found product image url. %s", product.url)

            # Their image URL is relative so we have to concat the shop's base URL with it.
            absoluteImageURL = urllib.parse.urljoin(self.URL, urlThumb)

            if not product.urlThumb or product.urlThumb != absoluteImageURL:
                product.urlThumb = absoluteImageURL
                isProductChanged = True  # note that we never switch back to False

        finally:
            return isProductChanged
コード例 #3
0
    async def _setProductThumbUrl(self, soup: BeautifulSoup, product: Product) -> ProductChanged:
        isProductChanged = False

        try:
            urlThumb = soup.find("li", class_="thumbnail-1") \
                .find("div", class_="wrap") \
                .img["src"]

            # Below code possibly superfluous. The above urlThumb is already valid,
            # but for mighty reasons linking to it in Discord seems to get blocked by BSTN. There's
            # a way to shorten the URL, as the last parts of the URL don't seem to be relevant.
            # Anyway, this won't fix the blocked link in Discord.
            # Example
            # https://www.bstn.com/media/140801/w/280/h/280/n/adidas-zx-8000-fv3269-1.jpg
            # is converted to
            # https://www.bstn.com/media/140801/w/280/h/280/n/0.jpg
            # match = re.search(r".*/h/280/n/", urlThumb)
            # urlThumb = f"{match.group()}0.jpg"

            if not urlThumb: raise AttributeError("No matches in HTML tree.")

        except AttributeError as e:
            logger.warning("Failed finding product image url. %s. %s", e, product.url)
            self._failCount += 1

        else:
            logger.debug("Found product image url. %s", product.url)
            if not product.urlThumb or product.urlThumb != urlThumb:
                product.urlThumb = urlThumb
                isProductChanged = True  # note that we never switch back to False

        finally:
            return isProductChanged
コード例 #4
0
    async def _setProductThumbUrl(self, soup: BeautifulSoup,
                                  product: Product) -> ProductChanged:
        isProductChanged = False

        try:
            urlThumb = soup.find("div", {"class": "b-pdp-product-preview-wrapper"}) \
                .find("div", {"class": "b-pdp-carousel-item"}) \
                .div["data-default-src"]

            if not urlThumb: raise AttributeError("No matches in HTML tree.")

        except AttributeError as e:
            logger.warning("Failed finding product image url. %s. %s", e,
                           product.url)
            self._failCount += 1

        else:
            logger.debug("Found product image url. %s", product.url)
            if not product.urlThumb or product.urlThumb != urlThumb:
                product.urlThumb = urlThumb
                isProductChanged = True  # note that we never switch back to False

        finally:
            return isProductChanged
コード例 #5
0
    def create2Shops(self) -> None:
        """ Caution: Do not change values as they are tested against
        :return: None
        """
        size01 = Size()
        size01.uid = str(
            uuid.UUID(hex="1528dae6-188f-4d7e-8a6c-5af44ce5c222", version=4))
        size01.sizeEU = "40 1/3"
        size01.isInStock = True
        size01.price = 56.99
        size01.url = "http://oneshop.com/bottles/92743867ACTFGJ-UTU/40.1.3.htm"
        size01.urlAddToCart = "http://oneshop.com/bottles/atc/40.1.3-92743867ACTFGJ-UTU.htm"

        size02 = Size()
        size02.uid = str(
            uuid.UUID(hex="5f561c62-8502-4ec1-8f46-f0adb5e8254c", version=4))
        size02.sizeEU = "43"
        size02.isInStock = False
        size02.price = 54.99
        size02.url = "http://oneshop.com/bottles/92743867ACTFGJ-UTU/43.htm"
        size02.urlAddToCart = "http://oneshop.com/bottles/atc/43-92743867ACTFGJ-UTU.htm"

        size03 = Size()
        size03.uid = str(
            uuid.UUID(hex="e070b0c9-769d-4c13-a208-f7207f0970db", version=4))
        size03.sizeEU = "44.5"
        size03.isInStock = True
        size03.price = 189.50
        size03.url = "https://megashop.com/shoes/44.5-9a734hd78.htm"
        size03.urlAddToCart = "https://megashop.com/shoes/atc/44.5-9a734hd78#g89.php"

        product01 = Product()
        product01.uid = str(
            uuid.UUID(hex="2857027b-cf25-4639-965e-0e22f9f4c755", version=4))
        product01.url = "http://oneshop.com/bottles/92743867ACTFGJ-UTU"
        product01.name = "Biggest Corona Bottle ever"
        product01.setReleaseDate(dtt.datetime(2020, 9, 30, 13, 50, 59),
                                 timezone="Europe/Berlin")
        product01.basePrice = 55.49
        product01.lastScanStamp = 1588548868.304869  # setLastScanNow()
        product01.sizes = [size01, size02]

        product02 = Product()
        product02.uid = str(
            uuid.UUID(hex="9cab557a-419a-4883-8287-f09f7244b225", version=4))
        product02.url = "http://oneshop.com/bottles/1362836400447GT-UTU"
        product02.name = "Neck Bottle"
        product02.setReleaseDate(dtt.datetime(2023, 1, 30, 15, 40, 35),
                                 timezone="Europe/Berlin")
        product02.basePrice = 3.22
        product02.lastScanStamp = 1588548911.230381  # setLastScanNow()
        product02.sizes = []

        product03 = Product()
        product03.uid = str(
            uuid.UUID(hex="f0700293-693c-48a6-8f01-014e07151d99", version=4))
        product03.url = "https://www.megashop.com/shoes/9a734hd78.html"
        product03.urlThumb = "https://www.megashop.com/shoes/thumb-9a734hd78.html"
        product03.name = "Hey Bro Male"
        product03.setReleaseDate(dtt.datetime(2028, 11, 1, 8, 2, 40),
                                 timezone="Europe/Berlin")
        product03.basePrice = 190
        product03.lastScanStamp = 1588548274.102859  # setLastScanNow()
        product03.sizes = [size03]

        shop01 = Shop()
        # ID is usually set by the DBMS, we explicitly set it for equality checks, too:
        shop01.uid = str(
            uuid.UUID(hex="73f9cac8-ebdc-4d9b-8163-d04d09f06cd9", version=4))
        shop01.name = "Bottle shop"
        shop01.url = "http://oneshop.com/bottles"
        shop01.products = [product01, product02]

        shop02 = Shop()
        # ID is usually set by the DBMS, we explicitly set it for equality checks, too:
        shop02.uid = str(
            uuid.UUID(hex="69ec8e1b-8812-4413-ad72-b74364e2fa7a", version=4))
        shop02.name = "Megashop"
        shop02.url = "https://www.megashop.com/shoes"
        shop02.products = [product03]

        self.shops = [shop01, shop02]