Example #1
0
    def test_extract_file_from_archive(self):
        os.makedirs(TESTDATA_NEW_PATH)
        test_zip_archive = os.path.join(TESTDATA_NEW_PATH, 'letterboxd.zip')
        copyfile(os.path.join(TESTDATA_PATH, 'letterboxd', 'my_ratings.zip'), test_zip_archive)
        extracted_file = os.path.join(TESTDATA_NEW_PATH, 'ratings.csv')

        self.assertTrue(os.path.isfile(test_zip_archive))
        self.assertFalse(os.path.isfile(extracted_file))

        file_impex.extract_file_from_archive(test_zip_archive, 'ratings.csv', TESTDATA_NEW_PATH)

        self.assertFalse(os.path.isfile(test_zip_archive))
        self.assertTrue(os.path.isfile(extracted_file))

        os.remove(extracted_file)
        os.removedirs(TESTDATA_NEW_PATH)
    def _parse_ratings(self):
        self.before = os.listdir(self.exports_folder)  # pylint: disable=attribute-defined-outside-init
        self._download_ratings_csv()

        after = os.listdir(self.exports_folder)
        change = self._get_downloaded_filename(after, self.before)
        if len(change) == 1:
            archive_filename = change.pop(
            )  # the one file that was added to the dir
            file_impex.extract_file_from_archive(
                os.path.join(self.exports_folder, archive_filename),
                self.downloaded_file_name, self.exports_folder)
            self._rename_csv_file(self.downloaded_file_name)
            self.movies = self._parse_movies_from_csv(
                os.path.join(self.exports_folder, self.csv_filename))
        else:
            command_line.error('Could not determine file location')
    def _parse_ratings(self):
        before = os.listdir(self.exports_folder)
        self._download_ratings_csv()

        after = os.listdir(self.exports_folder)
        change = self._get_downloaded_filename(after, before)
        if len(change) == 1:
            archive_filename = change.pop()  # the one file that was added to the dir
            ratings_csv_filename = 'ratings.csv'
            file_impex.extract_file_from_archive(
                os.path.join(self.exports_folder, archive_filename),
                ratings_csv_filename,
                self.exports_folder
            )
            self._rename_csv_file('ratings.csv')
            self.movies = self._parse_movies_from_csv(os.path.join(self.exports_folder, self.csv_filename))
        else:
            command_line.error('Could not determine file location')
Example #4
0
    def _parse_ratings(self):
        before = os.listdir(self.exports_folder)
        self._download_ratings_csv()

        after = os.listdir(self.exports_folder)
        change = self._get_downloaded_filename(after, before)
        if len(change) == 1:
            archive_filename = change.pop(
            )  # the one file that was added to the dir
            ratings_csv_filename = 'ratings.csv'
            file_impex.extract_file_from_archive(
                os.path.join(self.exports_folder, archive_filename),
                ratings_csv_filename, self.exports_folder)
            self._rename_csv_file()
            self.movies = self._parse_movies_from_csv(
                os.path.join(self.exports_folder, self.csv_filename))
        else:
            sys.stdout.write('\r===== %s: Could not determine file -- ABORT' %
                             self.site.site_name)
            sys.stdout.flush()