def fetch_article(self): """ Fetches a title and a readable_article for the current url. It uses the scrapers module for this and only downloads the content. """ dl = download(self.url, max_content_length=settings.PYPO_MAX_CONTENT_LENGTH) self.title, self.readable_article = parse(self, content_type=dl.content_type, text=dl.text, content=dl.content)
def fetch_article(self): """ Fetches a title and a readable_article for the current url. It uses the scrapers module for this and only downloads the content. """ try: dl = download(self.url, max_content_length=settings.PYPO_MAX_CONTENT_LENGTH) except DownloadException: # TODO show a message that the download failed? self.title = self.url self.readable_article = None else: self.title, self.readable_article = parse(self, content_type=dl.content_type, text=dl.text, content=dl.content)
def test_invalid_html(user): item = Item.objects.create(url='http://some_invalid_localhost', title='nothing', owner=user) assert (item.url, '') == parse(item, content_type='text/html', text=None)
def test_invalid_html(self): item = Item.objects.create(url='http://some_invalid_localhost', domain='nothing', owner=User.objects.get(pk=1)) self.assertEqual((item.url, ''), parse(item, content_type='text/html', text=None))