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/*
|
books/*
|
||||||
data/shelf.json
|
*.json
|
||||||
*.pyc
|
*.pyc
|
||||||
File diff suppressed because one or more lines are too long
10
library.py
10
library.py
@@ -15,8 +15,7 @@ class Catalogue:
|
|||||||
self.catalogue = json.load(f)
|
self.catalogue = json.load(f)
|
||||||
self.current_files = self.scan_folder()
|
self.current_files = self.scan_folder()
|
||||||
except Exception:
|
except Exception:
|
||||||
with open(config.book_shelf, 'w') as f:
|
self.filter_books()
|
||||||
json.dump(self.filter_books(), f)
|
|
||||||
|
|
||||||
def scan_folder(self, folder=config.book_path):
|
def scan_folder(self, folder=config.book_path):
|
||||||
for f in os.listdir(folder):
|
for f in os.listdir(folder):
|
||||||
@@ -27,12 +26,15 @@ class Catalogue:
|
|||||||
self.file_list.append(self.scan_folder(_path))
|
self.file_list.append(self.scan_folder(_path))
|
||||||
self.file_list.append(_path)
|
self.file_list.append(_path)
|
||||||
|
|
||||||
def filter_books(self):
|
def filter_books(self, ret=0):
|
||||||
scan = self.scan_folder()
|
self.scan_folder()
|
||||||
regx = re.compile(r"\.epub")
|
regx = re.compile(r"\.epub")
|
||||||
self.books = list(filter(regx.search, filter(None, self.file_list)))
|
self.books = list(filter(regx.search, filter(None, self.file_list)))
|
||||||
|
if ret == 0:
|
||||||
with open(config.book_shelf, 'w') as f:
|
with open(config.book_shelf, 'w') as f:
|
||||||
json.dump(self.books, f)
|
json.dump(self.books, f)
|
||||||
|
else:
|
||||||
|
return self.books
|
||||||
|
|
||||||
def compare_shelf_current(self):
|
def compare_shelf_current(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Binary file not shown.
@@ -10,9 +10,5 @@ class Testing(unittest.TestCase):
|
|||||||
def test_library_catalogue_filter_books(self):
|
def test_library_catalogue_filter_books(self):
|
||||||
self.assertIsNotNone(Catalogue().filter_books())
|
self.assertIsNotNone(Catalogue().filter_books())
|
||||||
|
|
||||||
def test_library_catalogue_compare_shelf_current(self):
|
|
||||||
self.assertIsInstance(Catalogue().compare_shelf_current(), Catalogue)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user