Staging for transfer

This commit is contained in:
Mike
2019-10-13 13:04:40 -04:00
parent eeeb8631c4
commit a1bb0aa101
5 changed files with 19 additions and 25 deletions

File diff suppressed because one or more lines are too long

View File

@@ -6,7 +6,7 @@ import zipfile
from PIL import Image from PIL import Image
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from config import Config from config import Config
from api_hooks import DuckDuckGo from lib.api_hooks import DuckDuckGo
config = Config() config = Config()
@@ -19,14 +19,6 @@ class Catalogue:
self.opf_regx = re.compile(r'\.opf') self.opf_regx = re.compile(r'\.opf')
self.cover_regx = re.compile(r'\.jpg|\.jpeg|\.png|\.bmp|\.gif') self.cover_regx = re.compile(r'\.jpg|\.jpeg|\.png|\.bmp|\.gif')
self.html_regx = re.compile(r'\.html') self.html_regx = re.compile(r'\.html')
"""
with open(config.book_shelf, 'r') as f:
try:
self.catalogue = json.load(f)
self.current_files = self.scan_folder()
except Exception:
self.filter_books()
"""
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):
@@ -44,7 +36,7 @@ class Catalogue:
try: _epub_open.open('content.opf'); return True try: _epub_open.open('content.opf'); return True
except Exception as e: print(e); return False except Exception as e: print(e); return False
def filter_books(self): def filter_books(self, ret=0):
""" """
Scan book folder recursively for epub files Scan book folder recursively for epub files
filter_books(0) -> Catalogue.books filter_books(0) -> Catalogue.books
@@ -59,8 +51,11 @@ class Catalogue:
with open(config.book_shelf, 'w') as f: with open(config.book_shelf, 'w') as f:
for book in self.books: for book in self.books:
_book_list_expanded[book] = self.process_book(book) _book_list_expanded[book] = self.process_book(book)
json.dump(_book_list_expanded, f) if ret != 0: return _book_list_expanded
return _book_list_expanded else:
import ipdb; ipdb.set_trace()
json.dump(_book_list_expanded, f)
return _book_list_expanded
def process_book(self, book): def process_book(self, book):
"""Return dictionary of epub file contents""" """Return dictionary of epub file contents"""
@@ -133,6 +128,6 @@ class Catalogue:
try: try:
self.books self.books
except Exception: except Exception:
self.filter_books() self.filter_books(1)
unique = set(self.books) - set(self.catalogue) unique = set(self.books) - set(self.catalogue)
return unique return unique

View File

@@ -1,16 +1,16 @@
import unittest import unittest
import sys import sys
sys.path.insert(1, 'lib/') sys.path.insert(1, '../')
from library import Catalogue from lib.library import Catalogue
Catalogue = Catalogue()
class LibraryTest(unittest.TestCase): class LibraryTest(unittest.TestCase):
def test_libray_catalogue(self): def test_libray_catalogue(self):
self.assertIsNotNone(Catalogue()) self.assertIsNotNone(Catalogue)
def test_library_catalogue_filter_books(self): def test_library_catalogue_filter_books(self):
self.assertIsNotNone(Catalogue().filter_books()) self.assertIsNotNone(Catalogue.filter_books())
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@@ -1,7 +1,7 @@
import unittest import unittest
import sys import sys
sys.path.insert(1, 'lib/') sys.path.insert(1, '../')
from storage import Storage from lib.storage import Storage
storage = Storage() storage = Storage()
@@ -13,4 +13,4 @@ class StorageTest(unittest.TestCase):
def test_Storage_create_tables(self): def test_Storage_create_tables(self):
self.assertIsNot(storage.create_tables(), Exception) self.assertIsNot(storage.create_tables(), Exception)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@@ -2,9 +2,9 @@ import unittest
import os import os
import shutil import shutil
import sys import sys
sys.path.insert(1, 'lib/') sys.path.insert(1, '../')
from pyShelf import InitFiles from lib.pyShelf import InitFiles
from pyShelf import Epub from lib.pyShelf import Epub
class SysIoTest(unittest.TestCase): class SysIoTest(unittest.TestCase):