class IgnoreFilteredLinksTestCase(unittest.TestCase):

    def setUp(self):
        self.thread_dir = TemporaryDirectory(dir=TMP_DIRECTORY)
        self.downloader = BatchDownloader(LinksRetriever(STICKY_THREAD_URL), self.thread_dir.name)
        self.ignore = [os.path.basename(url) for url in ('http://i.4cdn.org/wg/1489266876258.png', 'http://i.4cdn.org/wg/1489266748255.jpg')]
        self.ifilter = IgnoreFilter(self.ignore, is_regex=True)
        self.downloader.ifilter = self.ifilter

    def test_num_links(self):
        links = tuple(self.downloader.links())
        self.assertGreater(len(links), 0)
        self.assertEqual(len(links), len(self.downloader.get_links_not_downloaded()) - len(self.ignore))
        print('Links tuple:', links)
Beispiel #2
0
def create_test_environment(dirname,
                            num_files_to_download=0,
                            url=TEST_THREAD_FILENAME):
    utilities.create_directory_tree(dirname)

    # Create pickle
    downloader = BatchDownloader(LinksRetriever(url), dirname)
    downloader.pickle_details()

    # Create filter
    ifilter = utilities.IgnoreFilter(['\w+\.png'], is_regex=True)
    ifilter.save(os.path.join(dirname, downloader.IGNORE_LIST_FILENAME))

    # Download the first/top 3 images from the thread
    for url in downloader.links()[:num_files_to_download]:
        utilities.download_file(url, dirname)