Example #1
0
    def create_thumbnail(self) -> tuple:
        url = self._url
        thumbnail_path = None

        try:
            response = requests.get(url)
        except requests.exceptions.ConnectionError:
            raise InvalidURLException('url is not valid')

        if response.status_code > 300:
            raise InvalidURLException('url is not valid')

        og_handler = OgImageHandler(response)
        favicon_handler = FaviconHandler(response)

        name = self.__get_title(response)

        if og_handler.has_og_image_meta():
            thumbnail_path = og_handler.get_url()

        elif favicon_handler.set_favicon_image_link_tag(
        ) or favicon_handler.set_image_meta_tag():
            thumbnail_path = favicon_handler.get_url()
        else:
            return None, name

        thumbnail_path = self.__pad_host(thumbnail_path)

        return thumbnail_path, name
Example #2
0
 def test_get_url_return_link_ref_attrs(self):
     self.mock_res.text = """
         <html>
             <head>
                 <link rel="icon" href="test_favicon"/>
             </head>
             <body>
             </body>
         </html>
     """
     handler = FaviconHandler(self.mock_res)
     result = handler.set_favicon_image_link_tag()
     self.assertTrue(result)
     url = handler.get_url()
     self.assertIsNotNone(url)
     self.assertEqual('test_favicon', url)
Example #3
0
    def test_get_url_return_meta_content(self):
        self.mock_res.text = """
            <html>
                <head>
                    <meta itemprop="image" content="testmeta"/>
                </head>
                <body>
                </body>
            </html>
        """
        handler = FaviconHandler(self.mock_res)
        result = handler.set_image_meta_tag()
        self.assertTrue(result)

        url = handler.get_url()

        self.assertIsNotNone(url)
        self.assertEqual('testmeta', url)