mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
added argument to return filtered book list
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,3 @@
|
||||
books/*
|
||||
data/shelf.json
|
||||
*.json
|
||||
*.pyc
|
||||
File diff suppressed because one or more lines are too long
14
library.py
14
library.py
@@ -15,8 +15,7 @@ class Catalogue:
|
||||
self.catalogue = json.load(f)
|
||||
self.current_files = self.scan_folder()
|
||||
except Exception:
|
||||
with open(config.book_shelf, 'w') as f:
|
||||
json.dump(self.filter_books(), f)
|
||||
self.filter_books()
|
||||
|
||||
def scan_folder(self, folder=config.book_path):
|
||||
for f in os.listdir(folder):
|
||||
@@ -27,12 +26,15 @@ class Catalogue:
|
||||
self.file_list.append(self.scan_folder(_path))
|
||||
self.file_list.append(_path)
|
||||
|
||||
def filter_books(self):
|
||||
scan = self.scan_folder()
|
||||
def filter_books(self, ret=0):
|
||||
self.scan_folder()
|
||||
regx = re.compile(r"\.epub")
|
||||
self.books = list(filter(regx.search, filter(None, self.file_list)))
|
||||
with open(config.book_shelf, 'w') as f:
|
||||
json.dump(self.books, f)
|
||||
if ret == 0:
|
||||
with open(config.book_shelf, 'w') as f:
|
||||
json.dump(self.books, f)
|
||||
else:
|
||||
return self.books
|
||||
|
||||
def compare_shelf_current(self):
|
||||
try:
|
||||
|
||||
Binary file not shown.
@@ -10,9 +10,5 @@ class Testing(unittest.TestCase):
|
||||
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)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user