diff --git a/.gitignore b/.gitignore index 4cf998c..58b6342 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ books/* +data/shelf.json +*.pyc \ No newline at end of file diff --git a/__pycache__/library.cpython-37.pyc b/__pycache__/library.cpython-37.pyc index 928ec1c..583d9ee 100644 Binary files a/__pycache__/library.cpython-37.pyc and b/__pycache__/library.cpython-37.pyc differ diff --git a/library.py b/library.py index ae0520c..d65cf6f 100755 --- a/library.py +++ b/library.py @@ -9,6 +9,7 @@ config = Config() class Catalogue: """Decodes and stores book information""" def __init__(self): + self.file_list = [] with open(config.book_shelf, 'r') as f: try: self.catalogue = json.load(f) @@ -17,24 +18,26 @@ class Catalogue: with open(config.book_shelf, 'w') as f: json.dump(self.filter_books(), f) - def scan_folder(self): - file_list = [] - for f in os.listdir(config.book_path): - file_list.append(f) - return file_list + def scan_folder(self, folder=config.book_path): + for f in os.listdir(folder): + _path = os.path.abspath(folder+'/'+f) + #_path = os.path.abspath('.')+'/'+folder+f+'/' + _is_dir = os.path.isdir(_path.strip()+'/') + if _is_dir: + self.file_list.append(self.scan_folder(_path)) + self.file_list.append(_path) def filter_books(self): scan = self.scan_folder() - breakpoint() regx = re.compile(r"\.epub") - self.books = list(filter(regx.search, scan)) - return self.books + self.books = list(filter(regx.search, filter(None, self.file_list))) + with open(config.book_shelf, 'w') as f: + json.dump(self.books, f) def compare_shelf_current(self): try: self.books except Exception: self.filter_books() - breakpoint() unique = set(self.books) - set(self.catalogue) return unique diff --git a/tests/__pycache__/test_library.cpython-37.pyc b/tests/__pycache__/test_library.cpython-37.pyc index d9d8f8e..9babb42 100644 Binary files a/tests/__pycache__/test_library.cpython-37.pyc and b/tests/__pycache__/test_library.cpython-37.pyc differ diff --git a/tests/test_library.py b/tests/test_library.py index 3b4a59b..c51683c 100755 --- a/tests/test_library.py +++ b/tests/test_library.py @@ -7,8 +7,8 @@ class Testing(unittest.TestCase): def test_libray_catalogue(self): self.assertIsNotNone(Catalogue()) - def test_library_catalogue_scan_folder(self): - self.assertIsInstance(Catalogue().scan_folder(), object) + def test_library_catalogue_filter_books(self): + self.assertIsNotNone(Catalogue().filter_books()) def test_library_catalogue_compare_shelf_current(self): self.assertIsInstance(Catalogue().compare_shelf_current(), Catalogue)