Beispiel #1
0
def test_live_postimg(tmpdir, testdata):
    fn = tmpdir.strpath + '/aaa.jpg'
    base.download_images([('http://www.postimg.org/image/n467ovtd9/', fn)])
    assert len(os.listdir(
        tmpdir.strpath)) == 1, 'One images shall be downloaded'
    assert filecmp.cmp(testdata.fn('postimg.org.jpg'), fn, shallow=False), \
        'Downloaded image does not match the reference one'
Beispiel #2
0
def test_live_vfl(tmpdir, testdata):
    fn = tmpdir.strpath + '/aaa.jpg'
    base.download_images([('http://vfl.ru/fotos/b2203fcd18453338.html', fn)])
    assert len(os.listdir(
        tmpdir.strpath)) == 1, 'One images shall be downloaded'
    assert filecmp.cmp(
        testdata.fn('vfl.ru.jpg'), fn,
        shallow=False), 'Downloaded image does not match the reference one'
Beispiel #3
0
def test_live_radikal(tmpdir, testdata):
    fn = tmpdir.strpath + '/aaa.jpg'
    base.download_images([(
        'http://radikal.ru/F/s39.radikal.ru/i084/1106/a9/e1fca250702b.jpg.html',
        fn)])
    assert len(os.listdir(
        tmpdir.strpath)) == 1, 'One images shall be downloaded'
    assert filecmp.cmp(
        testdata.fn('radikal.ru.jpg'), fn,
        shallow=False), 'Downloaded image does not match the reference one'
Beispiel #4
0
def test_keep4u(tmpdir, testdata):
    fn = tmpdir.strpath + '/aaa.jpg'
    base.download_images([
        ('http://keep4u.ru/full/486422e15f82de157a64237a9627892e.html', fn)
    ])
    assert len(os.listdir(
        tmpdir.strpath)) == 1, 'One images shall be downloaded'
    assert filecmp.cmp(
        testdata.fn('keep4u.ru.jpg'), fn,
        shallow=False), 'Downloaded image does not match the reference one'
Beispiel #5
0
    def save(self, dest, use_title=True, write_url_file=True):
        """
        save found images to destination location
        :param dest: folder where to store images
        :param use_title: use title to create subfolder in specified location
        :param write_url_file: create url file pointing to original location or not. Default: True
        :return: folder where the files were written
        """

        if use_title:
            dest = os.path.join(dest, util.sluggify(self.title))
            os.makedirs(dest, exist_ok=True)

        dl = [(url, os.path.join(dest, fn)) for (url, fn) in self.dl]
        download_images(dl)

        # make url file
        if write_url_file:
            with open(os.path.join(dest,
                                   util.sluggify(self.title) + '.url'),
                      'w') as f:
                f.write('[InternetShortcut]\nURL={}'.format(self.url))

        return dest
Beispiel #6
0
def test_download_images_bad_links(tmpdir):
    # wrong encoding ?
    dl = [('http://www.wrk.ru/forums/attachment.php?item=83381',
           '{}/aaa.jpg'.format(tmpdir))]
    base.download_images(dl)
    assert len(os.listdir(
        tmpdir.strpath)) == 0, 'No files shall be downloaded and no exception'

    # no site
    dl = [('http://www.suveniri-knigi.ru/index.php?kcena=220&kkorzina=3521',
           '{}/aaa.jpg'.format(tmpdir))]
    base.download_images(dl)
    assert len(os.listdir(
        tmpdir.strpath)) == 0, 'No files shall be downloaded and no exception'

    # bad link
    dl = [('http://radikal.ru/lfp/s39.radikal.ru/i084/1106/a9/1fca250702b.jpg',
           '{}/aaa.jpg'.format(tmpdir))]
    base.download_images(dl)
    assert len(os.listdir(
        tmpdir.strpath)) == 0, 'No files shall be downloaded and no exception'
Beispiel #7
0
def test_live_vfl_2020(tmpdir, testdata):
    fn = tmpdir.strpath + '/aaa.jpg'
    base.download_images([('http://vfl.ru/fotos/9b930dc417050203.html', fn)])
    assert len(os.listdir(
        tmpdir.strpath)) == 1, 'One images shall be downloaded'
Beispiel #8
0
def test_download_images(tmpdir):
    nfiles = 20
    dl = [('http://httpbin.org/image/jpeg', '{}/{:02d}.jpg'.format(tmpdir, i))
          for i in range(nfiles)]
    base.download_images(dl)
    assert len(os.listdir(tmpdir.strpath)) == nfiles, 'Wrong number of files'