From a1bb0aa101b5f746950dd78f66d389ac81ffb782 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 13 Oct 2019 13:04:40 -0400 Subject: [PATCH 1/7] Staging for transfer --- data/shelf.json | 1 - lib/library.py | 21 ++++++++------------- tests/test_library.py | 10 +++++----- tests/test_storage.py | 6 +++--- tests/test_sysio.py | 6 +++--- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/data/shelf.json b/data/shelf.json index 5efa207..e69de29 100644 --- a/data/shelf.json +++ b/data/shelf.json @@ -1 +0,0 @@ -{"/home/raelon/Projects/pyShelf/books/Python Tricks by Dan Bader.epub": {"files": ["content.opf", "media/cover-6x9.png", "cover.xhtml"], "path": "/home/raelon/Projects/pyShelf/books/Python Tricks by Dan Bader.epub"}, "/home/raelon/Projects/pyShelf/books/Automate the Boring Stuff with Python - Practical Programming for Total Beginners - 1st Edition (2015) (Pdf, Epub & Mobi) Gooner/Automate the Boring Stuff with Python (2015).epub": {"files": ["OEBPS/content.opf", "OEBPS/Images/cover00710.jpeg", "OEBPS/Text/cover_page.xhtml"], "path": "/home/raelon/Projects/pyShelf/books/Automate the Boring Stuff with Python - Practical Programming for Total Beginners - 1st Edition (2015) (Pdf, Epub & Mobi) Gooner/Automate the Boring Stuff with Python (2015).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Dune Chronicles (Dune 7)/Dune Chronicles 1 - Hunters of Dune.epub": {"files": ["OPS/xhtml/cover.html", "OPS/9780765312921.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Dune Chronicles (Dune 7)/Dune Chronicles 1 - Hunters of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Dune Chronicles (Dune 7)/Dune Chronicles 2 - The Sandworms of Dune.epub": {"files": ["OPS/package.opf", "OPS/xhtml/cover.html"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Dune Chronicles (Dune 7)/Dune Chronicles 2 - The Sandworms of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 1 - Sisterhood of Dune.epub": {"files": ["OEBPS/content.opf", "OEBPS/Text/cover.xml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 1 - Sisterhood of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 2 - Mentats of Dune.epub": {"files": ["OEBPS/content.opf", "OEBPS/Images/cover.jpeg"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 2 - Mentats of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 2.5 - Red Plague.epub": {"files": ["OEBPS/content.opf", "OEBPS/Text/cover.xhtml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 2.5 - Red Plague.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 3 - Navigators of Dune.epub": {"files": ["OEBPS/content.opf", "OEBPS/Text/cover.xhtml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 3 - Navigators of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Heroes of Dune/Heroes of Dune 1 - Paul of Dune.epub": {"files": ["OPS/package.opf", "OPS/xhtml/cover.xml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Heroes of Dune/Heroes of Dune 1 - Paul of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Heroes of Dune/Heroes of Dune 2 - The Winds of Dune.epub": {"files": ["OPS/package.opf", "OPS/xhtml/cover.xml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Heroes of Dune/Heroes of Dune 2 - The Winds of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/1 - Dune - Frank Herbert (1965).epub": {"files": ["OEBPS/package.opf", "OEBPS/cover.xml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/1 - Dune - Frank Herbert (1965).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/2 - Dune Messiah - Frank Herbert (1969).epub": {"files": ["OEBPS/9780575104426_oeb_opf_r1.opf", "OEBPS/9780575104426_oeb_cover_r1.html"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/2 - Dune Messiah - Frank Herbert (1969).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/3 - Children of Dune - Frank Herbert (1976).epub": {"files": ["OEBPS/9780575104402_oeb_cover_r1.html", "OEBPS/9780575104402_oeb_opf_r1.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/3 - Children of Dune - Frank Herbert (1976).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/4 - God Emperor Of Dune - Frank Herbert (1981).epub": {"files": ["OEBPS/9780575104440_oeb_opf_r1.opf", "OEBPS/9780575104440_oeb_cover_r1.html"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/4 - God Emperor Of Dune - Frank Herbert (1981).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/5 - Heretics of Dune - Frank Herbert (1984).epub": {"files": ["OEBPS/9780575104457_oeb_cover_r1.html", "OEBPS/9780575104457_oeb_opf_r1.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/5 - Heretics of Dune - Frank Herbert (1984).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/6 - Chapter House Dune - Frank Herbert (1985).epub": {"files": ["OEBPS/9780575104396_oeb_opf_r1.opf", "OEBPS/9780575104396_oeb_cover_r1.html"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/6 - Chapter House Dune - Frank Herbert (1985).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 1 - House Atreides.epub": {"files": ["OEBPS/content.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 1 - House Atreides.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 2 - House Harkonnen.epub": {"files": ["Herb_9780553897838_epub_opf_r1.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 2 - House Harkonnen.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 3 - House Corrino.epub": {"files": ["OPS/content.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 3 - House Corrino.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/CliffsNotes on Herbert's Dune & Other Works - L. David Allen.epub": {"files": ["OPS/images/cover.jpg", "OPS/content.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/CliffsNotes on Herbert's Dune & Other Works - L. David Allen.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/Dreamer of Dune- The Biography of Frank Herbert by Brian Herbert.epub": {"files": ["OEBPS/content.opf", "OEBPS/Images/cover.jpg"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/Dreamer of Dune- The Biography of Frank Herbert by Brian Herbert.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/Eye (Short stories) - Frank Herbert.epub": {"files": ["OEBPS/content.opf", "OEBPS/Text/cover.xhtml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/Eye (Short stories) - Frank Herbert.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/Tales of Dune (Short stories) - Brian Herbert and Kevin J. Anderson.epub": {"files": ["OEBPS/content.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/Tales of Dune (Short stories) - Brian Herbert and Kevin J. Anderson.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/The Road to Dune (Companion book) - Frank Herbert et al.epub": {"files": ["OEBPS/e9781429924917_cover.jpg", "OEBPS/e9781429924917_content.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/The Road to Dune (Companion book) - Frank Herbert et al.epub"}} \ No newline at end of file diff --git a/lib/library.py b/lib/library.py index 9aef092..0f343b0 100755 --- a/lib/library.py +++ b/lib/library.py @@ -6,7 +6,7 @@ import zipfile from PIL import Image from bs4 import BeautifulSoup from config import Config -from api_hooks import DuckDuckGo +from lib.api_hooks import DuckDuckGo config = Config() @@ -19,14 +19,6 @@ class Catalogue: self.opf_regx = re.compile(r'\.opf') self.cover_regx = re.compile(r'\.jpg|\.jpeg|\.png|\.bmp|\.gif') 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): for f in os.listdir(folder): @@ -44,7 +36,7 @@ class Catalogue: try: _epub_open.open('content.opf'); return True 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 filter_books(0) -> Catalogue.books @@ -59,8 +51,11 @@ class Catalogue: with open(config.book_shelf, 'w') as f: for book in self.books: _book_list_expanded[book] = self.process_book(book) - json.dump(_book_list_expanded, f) - return _book_list_expanded + if ret != 0: 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): """Return dictionary of epub file contents""" @@ -133,6 +128,6 @@ class Catalogue: try: self.books except Exception: - self.filter_books() + self.filter_books(1) unique = set(self.books) - set(self.catalogue) return unique diff --git a/tests/test_library.py b/tests/test_library.py index a6b9be7..0df85af 100755 --- a/tests/test_library.py +++ b/tests/test_library.py @@ -1,16 +1,16 @@ import unittest import sys -sys.path.insert(1, 'lib/') -from library import Catalogue - +sys.path.insert(1, '../') +from lib.library import Catalogue +Catalogue = Catalogue() class LibraryTest(unittest.TestCase): def test_libray_catalogue(self): - self.assertIsNotNone(Catalogue()) + self.assertIsNotNone(Catalogue) def test_library_catalogue_filter_books(self): - self.assertIsNotNone(Catalogue().filter_books()) + self.assertIsNotNone(Catalogue.filter_books()) if __name__ == '__main__': unittest.main() diff --git a/tests/test_storage.py b/tests/test_storage.py index 48e632c..5a14cb8 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -1,7 +1,7 @@ import unittest import sys -sys.path.insert(1, 'lib/') -from storage import Storage +sys.path.insert(1, '../') +from lib.storage import Storage storage = Storage() @@ -13,4 +13,4 @@ class StorageTest(unittest.TestCase): def test_Storage_create_tables(self): self.assertIsNot(storage.create_tables(), Exception) if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() diff --git a/tests/test_sysio.py b/tests/test_sysio.py index b245522..31ea441 100755 --- a/tests/test_sysio.py +++ b/tests/test_sysio.py @@ -2,9 +2,9 @@ import unittest import os import shutil import sys -sys.path.insert(1, 'lib/') -from pyShelf import InitFiles -from pyShelf import Epub +sys.path.insert(1, '../') +from lib.pyShelf import InitFiles +from lib.pyShelf import Epub class SysIoTest(unittest.TestCase): From f821eb02cb638c83e9c3321db6b927067b3447c3 Mon Sep 17 00:00:00 2001 From: Raelon Masters Date: Mon, 14 Oct 2019 17:52:16 -0400 Subject: [PATCH 2/7] Implemented the return of unique files for storage --- __pycache__/config.cpython-37.pyc | Bin 623 -> 636 bytes config.py | 4 +- data/shelf.json | 1 + lib/api_hooks.py | 9 ++- lib/library.py | 68 +++++++++--------- lib/pyShelf.py | 13 ++-- lib/storage.py | 11 ++- main.py | 12 ++-- requirements.txt | 33 +++------ tests/__init__.py | 2 + tests/__pycache__/test_library.cpython-37.pyc | Bin 847 -> 1023 bytes tests/__pycache__/test_sysio.cpython-37.pyc | Bin 987 -> 951 bytes tests/test_library.py | 6 +- tests/test_storage.py | 2 +- tests/test_sysio.py | 2 +- 15 files changed, 87 insertions(+), 76 deletions(-) diff --git a/__pycache__/config.cpython-37.pyc b/__pycache__/config.cpython-37.pyc index c3590a7cb39a573c85d5f478bca6f2b6b7e9428a..fa48c0320dc87b23e42262ec783a9d4bfef4ecfd 100644 GIT binary patch delta 140 zcmaFQ@`r`jiI$DtBYoJsll+3^L5 zB^gm%U}kYfYEIg%$pMV|j4YEI7$=Id0gWhPK_yrxt1&67p$h`l+~Tmw%}*)KNws4H J@;(DG0{~&GBUk_c delta 127 zcmeyv@}7m)iI*QX>iK6U4T}7;@1lwd|CS^5rL7 create class property -> dump json :param ret: 1 -> create & return class property """ - self.scan_folder() - regx = re.compile(r"\.epub") - self.books = list(filter(regx.search, filter(None, self.file_list))) _book_list_expanded = {} with open(config.book_shelf, 'w') as f: for book in self.books: _book_list_expanded[book] = self.process_book(book) if ret != 0: return _book_list_expanded else: - import ipdb; ipdb.set_trace() json.dump(_book_list_expanded, f) return _book_list_expanded @@ -87,10 +92,12 @@ class Catalogue: title = soup.find("dc:title") if title == None: title = book['path'].split('/')[-1].rsplit('.', 1)[0] - else: title = title.contents[0] + else: + title = title.contents[0] author = soup.find("dc:creator") if author != None: author = author.contents[0] - try: cover = self.extract_cover_image(book_zip, book) + try: + cover = self.extract_cover_image(book_zip, book) except IndexError: # cover = self.extract_cover_html(book_zip, book) cover = DuckDuckGo().image_result(title) @@ -99,35 +106,32 @@ class Catalogue: def extract_content(self, book_zip, book): content = book_zip.open( - list( - filter(self.opf_regx.search, book['files']) - )[0] - ) + list(filter(self.opf_regx.search, book['files']))[0]) return content def extract_cover_html(self, book_zip, book): cover = book_zip.open( - list( - filter(self.html_regx.search, book['files']) - )[0] - ) + list(filter(self.html_regx.search, book['files']))[0]) return cover def extract_cover_image(self, book_zip, book): # TODO Handle books that have no Cover Image # TODO Handle books with html covers cover = book_zip.open( - list( - filter(self.cover_regx.search, book['files']) - )[0] - ) - try: cover = book_zip.read(cover.name); return cover - except KeyError: return False - - def compare_shelf_current(self): + list(filter(self.cover_regx.search, book['files']))[0]) try: - self.books + cover = book_zip.read(cover.name) + return cover + except KeyError: + return False + + def new_files(self): + storage = Storage() + try: + a = [] + stored = storage.book_paths_list() + for i in stored: a.append(i[-1]) + unique = set(self.books) - set(a) + return unique except Exception: - self.filter_books(1) - unique = set(self.books) - set(self.catalogue) - return unique + return False diff --git a/lib/pyShelf.py b/lib/pyShelf.py index d5da1cd..a5d7c2e 100755 --- a/lib/pyShelf.py +++ b/lib/pyShelf.py @@ -2,10 +2,12 @@ import os import zipfile from config import Config -from library import Catalogue -from storage import Storage +from lib.library import Catalogue +from lib.storage import Storage config = Config() Storage = Storage() + + class InitFiles: """First run file creation operations""" def __init__(self, file_array): @@ -18,7 +20,7 @@ class InitFiles: """Create the file""" if not os.path.isdir(os.path.split(_pointer)[0]): os.mkdir(os.path.split(_pointer)[0]) - f = open(_pointer, "w+") + f = open(_pointer, "w+") f.close() @@ -29,8 +31,9 @@ class Epub: self.book_path = config.book_path self.Catalogue = Catalogue() - def import_books(self): - book_list = self.Catalogue.filter_books() + def import_books(self, list=None): + if list is not None: book_list = list + else: book_list = self.Catalogue.filter_books() for book in book_list: extracted = self.Catalogue.extract_metadata(book_list[book]) Storage.insert_book(extracted) diff --git a/lib/storage.py b/lib/storage.py index a4b186e..57d0a25 100644 --- a/lib/storage.py +++ b/lib/storage.py @@ -1,7 +1,7 @@ #!/usr/bin/python import sys import sqlite3 -sys.path.insert(1,'../') +# sys.path.insert(1, '../') from config import Config db_pointer = Config().catalogue_db @@ -55,6 +55,13 @@ class Storage: print(e) return False + def book_paths_list(self): + q = '''SELECT file_name FROM books''' + x = self.cursor.execute(q) + try: x = x.fetchall() + except Exception: x = [] + return x + def commit(self): try: self.db.commit(); return True - except Exception as e: return False \ No newline at end of file + except Exception as e: return False diff --git a/main.py b/main.py index a665933..b5cdc69 100755 --- a/main.py +++ b/main.py @@ -1,19 +1,19 @@ #!/usr/bin/python import sys -from PIL import Image sys.path.insert(1, 'lib/') from pyShelf import InitFiles, Epub from config import Config from library import Catalogue -config = Config() # Get configuration settings -InitFiles(config.file_array) # Initialize file system -Catalogue = Catalogue() # Open the Catalogue +config = Config() # Get configuration settings +InitFiles(config.file_array) # Initialize file system +Catalogue = Catalogue() # Open the Catalogue # This only needs to be run on first run, & when new books are added -Epub().import_books() # Filter Your books +new_books = Catalogue.new_files() +Epub().import_books(new_books) # Filter Your books # TODO Implement file tracking system to avoid processing already tracked books # TODO Figure out a system to get books page count # TODO Update testing # TODO Update Documentation # TODO Requirements.txt -# TODO Test image storage \ No newline at end of file +# TODO Test image storage diff --git a/requirements.txt b/requirements.txt index 36bc418..770a533 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,23 +1,10 @@ -appdirs==1.4.3 -beautifulsoup4==4.8.0 -bs4==0.0.1 -certifi==2019.9.11 -chardet==3.0.4 -cssselect==1.1.0 -fake-useragent==0.1.11 -idna==2.8 -lxml==4.4.1 -parse==1.12.1 -Pillow==6.2.0 -pyee==6.0.0 -Pygments==2.4.2 -pyppeteer==0.0.25 -pyquery==1.4.0 -requests==2.22.0 -six==1.12.0 -soupsieve==1.9.4 -tqdm==4.36.1 -urllib3==1.25.6 -urwid==2.0.1 -w3lib==1.21.0 -websockets==8.0.2 \ No newline at end of file +bs4 +certifi +lxml +Pillow +requests +soupsieve +urllib3 +urwid +w3lib +websockets diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..b8bb7c9 100755 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,2 @@ +import sys +sys.path.insert(1, '../lib/') diff --git a/tests/__pycache__/test_library.cpython-37.pyc b/tests/__pycache__/test_library.cpython-37.pyc index 3a54b6d3827bb3e7a4e2d902e65c4e26e91ca42c..ac1de5e716636e67cf7eddb72698989a78ac038c 100644 GIT binary patch literal 1023 zcma)5&ubGw6n-_Ou|wHZ!$pH@kIagG9Wwe@Fse zy!rRc)sr4Qdh)$p)2xty1MlsdH}A*y&6_>i-Q59PzrKBW_mcs9r_E{wXdI%rV^kV6 z%OP#PEM>UoIiHGDFfifbF&gAD`!G^f~{WQKP zrzWsYs*VBu3UUQKe@oDxWcZk)+%ps46o<@KDismT#Z*$djy7h0Q>Z?g?hL# z`X4SdkDALq8V#2PUqYLYuoP5tNC)SWyfRjumF1O-nC;LB(P>l{E&piU)wV#YcIp5F zSBT@yh_~i$#(#hn*Z4JC^1l<|$;(LierqHRm0n>!5+<{a$Ac|A?(+6pB%b^SiMzxk z3cXaS$fiaqzoXQ&)U%xIfl?o4S>Bvji480b*Y-)R@42?N)I{t0p9eWf&@WN0SPI))wF3MyYbK>c&KL~Z2p?Y5CV;m6ZeTy%Ta=Q?4CL4tyx8v@`k zwkpglhHDE9OA<1*0~^pWVm5Og5py^iI}04RoHBP}i8GF>R*ke9E|5o;W`@56jdPO3 z!~J63huz|Nk7(5?Ui$}|TDnIS%3*!Pmi&FRo6ar=l diff --git a/tests/__pycache__/test_sysio.cpython-37.pyc b/tests/__pycache__/test_sysio.cpython-37.pyc index e54ebc184e9ec28040a8f2231c68a10c9aa89732..e7f67963bac4d2a86369d5dc907ce583b6dcbb6a 100644 GIT binary patch delta 331 zcmcc3zMY-diIEHtrx0s77i=()6GL!TQDuXjpbJB{KKyu6=IgSvZ zTIa;#RIpJ_MZzFK7LajBZUZ}m2dvyCH$SB`C)JJ-$SW2A5*&D}|Ydw1tA@gwB1lpW^I^TXR!x0E}OmV3Lg=2L$WC{OXF2TU>L zr>#sxqTzw#7$LAzrdmq8G9@&dwqJPE(OreNo|$O22$#%N!-x&rD;jXV0*8-&nq2Rf z@87_yOE`eA`hed7ZBT`u*6eMEn>eFq5Z+k+57-j@h}%#2FJ diff --git a/tests/test_library.py b/tests/test_library.py index 0df85af..8b4b03d 100755 --- a/tests/test_library.py +++ b/tests/test_library.py @@ -1,6 +1,6 @@ import unittest import sys -sys.path.insert(1, '../') +# sys.path.insert(1, '../') from lib.library import Catalogue Catalogue = Catalogue() @@ -12,5 +12,9 @@ class LibraryTest(unittest.TestCase): def test_library_catalogue_filter_books(self): self.assertIsNotNone(Catalogue.filter_books()) + def test_library_catalogue_new_files(self): + self.assertIsNot(Catalogue.new_files(), False) + + if __name__ == '__main__': unittest.main() diff --git a/tests/test_storage.py b/tests/test_storage.py index 5a14cb8..f3dabf5 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -1,6 +1,6 @@ import unittest import sys -sys.path.insert(1, '../') +# sys.path.insert(1, '../') from lib.storage import Storage storage = Storage() diff --git a/tests/test_sysio.py b/tests/test_sysio.py index 31ea441..8e50b36 100755 --- a/tests/test_sysio.py +++ b/tests/test_sysio.py @@ -2,7 +2,7 @@ import unittest import os import shutil import sys -sys.path.insert(1, '../') +# sys.path.insert(1, '../') from lib.pyShelf import InitFiles from lib.pyShelf import Epub From 545b55a48612d1bb4a808aee31a30a24c38bb6ef Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 16 Oct 2019 09:12:56 -0400 Subject: [PATCH 3/7] workin on new book check system --- .#config.py | 1 + __pycache__/config.cpython-37.pyc | Bin 636 -> 623 bytes config.py | 2 +- data/shelf.json | 2 +- lib/library.py | 101 +++++++++--------- lib/pyShelf.py | 19 ---- main.py | 9 +- tests/__pycache__/test_library.cpython-37.pyc | Bin 1023 -> 1023 bytes tests/__pycache__/test_sysio.cpython-37.pyc | Bin 951 -> 951 bytes 9 files changed, 59 insertions(+), 75 deletions(-) create mode 120000 .#config.py diff --git a/.#config.py b/.#config.py new file mode 120000 index 0000000..a046871 --- /dev/null +++ b/.#config.py @@ -0,0 +1 @@ +raelon@golumnsec.33289:1571093667 \ No newline at end of file diff --git a/__pycache__/config.cpython-37.pyc b/__pycache__/config.cpython-37.pyc index fa48c0320dc87b23e42262ec783a9d4bfef4ecfd..b9e701ecd6e7c93c2dd16945910f673dc2dae113 100644 GIT binary patch delta 115 zcmeyv@}7m)iIV+8U(12F>tz;qet delta 128 zcmaFQ@`r`jiI$Duq?oJsll+3^L5 zB^gnZT^OwyStd6yP84MWYAa$vC0Hk`F)6E|3j)>L;;_lhPbtkwwPOVGJ_9iW0PSiX AOaK4? diff --git a/config.py b/config.py index 4b39d88..bd5dcde 100755 --- a/config.py +++ b/config.py @@ -1,7 +1,7 @@ class Config: """Main System Configuration""" def __init__(self): - self.book_path = "/home/raelon/Books/" + self.book_path = "books/" self.book_shelf = "data/shelf.json" self.catalogue_db = "data/catalogue.db" self.file_array = [ diff --git a/data/shelf.json b/data/shelf.json index 4c4bc29..5efa207 100644 --- a/data/shelf.json +++ b/data/shelf.json @@ -1 +1 @@ -{"/home/raelon/Books/All Dune books + short stories + extras ePUB/Dune Chronicles (Dune 7)/Dune Chronicles 1 - Hunters of Dune.epub": {"files": ["OPS/xhtml/cover.html", "OPS/9780765312921.opf"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Dune Chronicles (Dune 7)/Dune Chronicles 1 - Hunters of Dune.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Dune Chronicles (Dune 7)/Dune Chronicles 2 - The Sandworms of Dune.epub": {"files": ["OPS/package.opf", "OPS/xhtml/cover.html"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Dune Chronicles (Dune 7)/Dune Chronicles 2 - The Sandworms of Dune.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 1 - Sisterhood of Dune.epub": {"files": ["OEBPS/content.opf", "OEBPS/Text/cover.xml"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 1 - Sisterhood of Dune.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 2 - Mentats of Dune.epub": {"files": ["OEBPS/content.opf", "OEBPS/Images/cover.jpeg"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 2 - Mentats of Dune.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 2.5 - Red Plague.epub": {"files": ["OEBPS/content.opf", "OEBPS/Text/cover.xhtml"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 2.5 - Red Plague.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 3 - Navigators of Dune.epub": {"files": ["OEBPS/content.opf", "OEBPS/Text/cover.xhtml"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 3 - Navigators of Dune.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Heroes of Dune/Heroes of Dune 1 - Paul of Dune.epub": {"files": ["OPS/package.opf", "OPS/xhtml/cover.xml"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Heroes of Dune/Heroes of Dune 1 - Paul of Dune.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Heroes of Dune/Heroes of Dune 2 - The Winds of Dune.epub": {"files": ["OPS/package.opf", "OPS/xhtml/cover.xml"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Heroes of Dune/Heroes of Dune 2 - The Winds of Dune.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Original Dune series/1 - Dune - Frank Herbert (1965).epub": {"files": ["OEBPS/package.opf", "OEBPS/cover.xml"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Original Dune series/1 - Dune - Frank Herbert (1965).epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Original Dune series/2 - Dune Messiah - Frank Herbert (1969).epub": {"files": ["OEBPS/9780575104426_oeb_opf_r1.opf", "OEBPS/9780575104426_oeb_cover_r1.html"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Original Dune series/2 - Dune Messiah - Frank Herbert (1969).epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Original Dune series/3 - Children of Dune - Frank Herbert (1976).epub": {"files": ["OEBPS/9780575104402_oeb_cover_r1.html", "OEBPS/9780575104402_oeb_opf_r1.opf"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Original Dune series/3 - Children of Dune - Frank Herbert (1976).epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Original Dune series/4 - God Emperor Of Dune - Frank Herbert (1981).epub": {"files": ["OEBPS/9780575104440_oeb_opf_r1.opf", "OEBPS/9780575104440_oeb_cover_r1.html"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Original Dune series/4 - God Emperor Of Dune - Frank Herbert (1981).epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Original Dune series/5 - Heretics of Dune - Frank Herbert (1984).epub": {"files": ["OEBPS/9780575104457_oeb_cover_r1.html", "OEBPS/9780575104457_oeb_opf_r1.opf"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Original Dune series/5 - Heretics of Dune - Frank Herbert (1984).epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Original Dune series/6 - Chapter House Dune - Frank Herbert (1985).epub": {"files": ["OEBPS/9780575104396_oeb_opf_r1.opf", "OEBPS/9780575104396_oeb_cover_r1.html"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Original Dune series/6 - Chapter House Dune - Frank Herbert (1985).epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 1 - House Atreides.epub": {"files": ["OEBPS/content.opf"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 1 - House Atreides.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 2 - House Harkonnen.epub": {"files": ["Herb_9780553897838_epub_opf_r1.opf"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 2 - House Harkonnen.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 3 - House Corrino.epub": {"files": ["OPS/content.opf"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 3 - House Corrino.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Short story collections and extras/CliffsNotes on Herbert's Dune & Other Works - L. David Allen.epub": {"files": ["OPS/images/cover.jpg", "OPS/content.opf"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Short story collections and extras/CliffsNotes on Herbert's Dune & Other Works - L. David Allen.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Short story collections and extras/Dreamer of Dune- The Biography of Frank Herbert by Brian Herbert.epub": {"files": ["OEBPS/content.opf", "OEBPS/Images/cover.jpg"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Short story collections and extras/Dreamer of Dune- The Biography of Frank Herbert by Brian Herbert.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Short story collections and extras/Eye (Short stories) - Frank Herbert.epub": {"files": ["OEBPS/content.opf", "OEBPS/Text/cover.xhtml"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Short story collections and extras/Eye (Short stories) - Frank Herbert.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Short story collections and extras/Tales of Dune (Short stories) - Brian Herbert and Kevin J. Anderson.epub": {"files": ["OEBPS/content.opf"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Short story collections and extras/Tales of Dune (Short stories) - Brian Herbert and Kevin J. Anderson.epub"}, "/home/raelon/Books/All Dune books + short stories + extras ePUB/Short story collections and extras/The Road to Dune (Companion book) - Frank Herbert et al.epub": {"files": ["OEBPS/e9781429924917_cover.jpg", "OEBPS/e9781429924917_content.opf"], "path": "/home/raelon/Books/All Dune books + short stories + extras ePUB/Short story collections and extras/The Road to Dune (Companion book) - Frank Herbert et al.epub"}, "/home/raelon/Books/Clancy/Clancy, Tom/Against All Enemies/Against All Enemies - Tom Clancy.epub": {"files": ["content.opf", "cover.jpeg"], "path": "/home/raelon/Books/Clancy/Clancy, Tom/Against All Enemies/Against All Enemies - Tom Clancy.epub"}, "/home/raelon/Books/Clancy/Clancy, Tom/Archimedes Effect, The/Archimedes Effect, The - Tom Clancy.epub": {"files": ["content.opf", "cover.jpeg"], "path": "/home/raelon/Books/Clancy/Clancy, Tom/Archimedes Effect, The/Archimedes Effect, The - Tom Clancy.epub"}, "/home/raelon/Books/Clancy/Clancy, Tom/Cardinal of the Kremlin, The/Cardinal of the Kremlin, The - Tom Clancy.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Clancy/Clancy, Tom/Cardinal of the Kremlin, The/Cardinal of the Kremlin, The - Tom Clancy.epub"}, "/home/raelon/Books/Clancy/Clancy, Tom/Dead or Alive/Dead or Alive - Tom Clancy.epub": {"files": ["content.opf", "cover.jpeg"], "path": "/home/raelon/Books/Clancy/Clancy, Tom/Dead or Alive/Dead or Alive - Tom Clancy.epub"}, "/home/raelon/Books/Clancy/Clancy, Tom/Debt of Honor/Debt of Honor - Tom Clancy.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Clancy/Clancy, Tom/Debt of Honor/Debt of Honor - Tom Clancy.epub"}, "/home/raelon/Books/Clancy/Clancy, Tom/Rainbow Six/Rainbow Six - Tom Clancy.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Clancy/Clancy, Tom/Rainbow Six/Rainbow Six - Tom Clancy.epub"}, "/home/raelon/Books/Clancy/Clancy, Tom/Red Storm Rising/Red Storm Rising - Tom Clancy.epub": {"files": ["content.opf", "cover.jpeg"], "path": "/home/raelon/Books/Clancy/Clancy, Tom/Red Storm Rising/Red Storm Rising - Tom Clancy.epub"}, "/home/raelon/Books/Clancy/Clancy, Tom/Springboard/Springboard - Tom Clancy.epub": {"files": ["content.opf", "cover.jpeg"], "path": "/home/raelon/Books/Clancy/Clancy, Tom/Springboard/Springboard - Tom Clancy.epub"}, "/home/raelon/Books/Clancy/Clancy, Tom/State of War/State of War - Tom Clancy.epub": {"files": ["content.opf", "cover.jpeg"], "path": "/home/raelon/Books/Clancy/Clancy, Tom/State of War/State of War - Tom Clancy.epub"}, "/home/raelon/Books/Coding The Bible 2 Manuscripts - Python and Raspberry PI/Coding The Bible 2 Manuscripts - Python and Raspberry PI.epub": {"files": ["OEBPS/content.opf"], "path": "/home/raelon/Books/Coding The Bible 2 Manuscripts - Python and Raspberry PI/Coding The Bible 2 Manuscripts - Python and Raspberry PI.epub"}, "/home/raelon/Books/Automate the Boring Stuff with Python - Practical Programming for Total Beginners - 1st Edition (2015) (Pdf, Epub & Mobi) Gooner/Automate the Boring Stuff with Python (2015).epub": {"files": ["OEBPS/content.opf", "OEBPS/Images/cover00710.jpeg", "OEBPS/Text/cover_page.xhtml"], "path": "/home/raelon/Books/Automate the Boring Stuff with Python - Practical Programming for Total Beginners - 1st Edition (2015) (Pdf, Epub & Mobi) Gooner/Automate the Boring Stuff with Python (2015).epub"}, "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Commodore, The - C. S. Forester.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Commodore, The - C. S. Forester.epub"}, "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Flying Colours - C. S. Forester.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Flying Colours - C. S. Forester.epub"}, "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Happy Return, The - C. S. Forester.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Happy Return, The - C. S. Forester.epub"}, "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Hornblower and the Atropos - C. S. Forester.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Hornblower and the Atropos - C. S. Forester.epub"}, "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Hornblower and the Crisis - C. S. Forester.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Hornblower and the Crisis - C. S. Forester.epub"}, "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Hornblower and the Hotspur - C. S. Forester.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Hornblower and the Hotspur - C. S. Forester.epub"}, "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Hornblower in the West Indies - C. S. Forester.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Hornblower in the West Indies - C. S. Forester.epub"}, "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Lieutenant Hornblower - C. S. Forester.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Lieutenant Hornblower - C. S. Forester.epub"}, "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Lord Hornblower - C. S. Forester.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Lord Hornblower - C. S. Forester.epub"}, "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Ship of the Line, A - C. S. Forester.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Ship of the Line, A - C. S. Forester.epub"}, "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Mr. Midshipman Hornblower - C. S. Forester.epub": {"files": ["content.opf", "cover1.jpeg"], "path": "/home/raelon/Books/Horatio Hornblower series by C. S. Forester/Mr. Midshipman Hornblower - C. S. Forester.epub"}} \ No newline at end of file +{"/home/raelon/Projects/pyShelf/books/Python Tricks by Dan Bader.epub": {"files": ["content.opf", "media/cover-6x9.png", "cover.xhtml"], "path": "/home/raelon/Projects/pyShelf/books/Python Tricks by Dan Bader.epub"}, "/home/raelon/Projects/pyShelf/books/Automate the Boring Stuff with Python - Practical Programming for Total Beginners - 1st Edition (2015) (Pdf, Epub & Mobi) Gooner/Automate the Boring Stuff with Python (2015).epub": {"files": ["OEBPS/content.opf", "OEBPS/Images/cover00710.jpeg", "OEBPS/Text/cover_page.xhtml"], "path": "/home/raelon/Projects/pyShelf/books/Automate the Boring Stuff with Python - Practical Programming for Total Beginners - 1st Edition (2015) (Pdf, Epub & Mobi) Gooner/Automate the Boring Stuff with Python (2015).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Dune Chronicles (Dune 7)/Dune Chronicles 1 - Hunters of Dune.epub": {"files": ["OPS/xhtml/cover.html", "OPS/9780765312921.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Dune Chronicles (Dune 7)/Dune Chronicles 1 - Hunters of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Dune Chronicles (Dune 7)/Dune Chronicles 2 - The Sandworms of Dune.epub": {"files": ["OPS/package.opf", "OPS/xhtml/cover.html"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Dune Chronicles (Dune 7)/Dune Chronicles 2 - The Sandworms of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 1 - Sisterhood of Dune.epub": {"files": ["OEBPS/content.opf", "OEBPS/Text/cover.xml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 1 - Sisterhood of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 2 - Mentats of Dune.epub": {"files": ["OEBPS/content.opf", "OEBPS/Images/cover.jpeg"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 2 - Mentats of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 2.5 - Red Plague.epub": {"files": ["OEBPS/content.opf", "OEBPS/Text/cover.xhtml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 2.5 - Red Plague.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 3 - Navigators of Dune.epub": {"files": ["OEBPS/content.opf", "OEBPS/Text/cover.xhtml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Great Schools of Dune/Great Schools of Dune 3 - Navigators of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Heroes of Dune/Heroes of Dune 1 - Paul of Dune.epub": {"files": ["OPS/package.opf", "OPS/xhtml/cover.xml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Heroes of Dune/Heroes of Dune 1 - Paul of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Heroes of Dune/Heroes of Dune 2 - The Winds of Dune.epub": {"files": ["OPS/package.opf", "OPS/xhtml/cover.xml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Heroes of Dune/Heroes of Dune 2 - The Winds of Dune.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/1 - Dune - Frank Herbert (1965).epub": {"files": ["OEBPS/package.opf", "OEBPS/cover.xml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/1 - Dune - Frank Herbert (1965).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/2 - Dune Messiah - Frank Herbert (1969).epub": {"files": ["OEBPS/9780575104426_oeb_opf_r1.opf", "OEBPS/9780575104426_oeb_cover_r1.html"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/2 - Dune Messiah - Frank Herbert (1969).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/3 - Children of Dune - Frank Herbert (1976).epub": {"files": ["OEBPS/9780575104402_oeb_cover_r1.html", "OEBPS/9780575104402_oeb_opf_r1.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/3 - Children of Dune - Frank Herbert (1976).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/4 - God Emperor Of Dune - Frank Herbert (1981).epub": {"files": ["OEBPS/9780575104440_oeb_opf_r1.opf", "OEBPS/9780575104440_oeb_cover_r1.html"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/4 - God Emperor Of Dune - Frank Herbert (1981).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/5 - Heretics of Dune - Frank Herbert (1984).epub": {"files": ["OEBPS/9780575104457_oeb_cover_r1.html", "OEBPS/9780575104457_oeb_opf_r1.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/5 - Heretics of Dune - Frank Herbert (1984).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/6 - Chapter House Dune - Frank Herbert (1985).epub": {"files": ["OEBPS/9780575104396_oeb_opf_r1.opf", "OEBPS/9780575104396_oeb_cover_r1.html"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Original Dune series/6 - Chapter House Dune - Frank Herbert (1985).epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 1 - House Atreides.epub": {"files": ["OEBPS/content.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 1 - House Atreides.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 2 - House Harkonnen.epub": {"files": ["Herb_9780553897838_epub_opf_r1.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 2 - House Harkonnen.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 3 - House Corrino.epub": {"files": ["OPS/content.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Prelude to Dune/Prelude to Dune 3 - House Corrino.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/CliffsNotes on Herbert's Dune & Other Works - L. David Allen.epub": {"files": ["OPS/images/cover.jpg", "OPS/content.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/CliffsNotes on Herbert's Dune & Other Works - L. David Allen.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/Dreamer of Dune- The Biography of Frank Herbert by Brian Herbert.epub": {"files": ["OEBPS/content.opf", "OEBPS/Images/cover.jpg"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/Dreamer of Dune- The Biography of Frank Herbert by Brian Herbert.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/Eye (Short stories) - Frank Herbert.epub": {"files": ["OEBPS/content.opf", "OEBPS/Text/cover.xhtml"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/Eye (Short stories) - Frank Herbert.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/Tales of Dune (Short stories) - Brian Herbert and Kevin J. Anderson.epub": {"files": ["OEBPS/content.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/Tales of Dune (Short stories) - Brian Herbert and Kevin J. Anderson.epub"}, "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/The Road to Dune (Companion book) - Frank Herbert et al.epub": {"files": ["OEBPS/e9781429924917_cover.jpg", "OEBPS/e9781429924917_content.opf"], "path": "/home/raelon/Projects/pyShelf/books/All Dune books + short stories + extras ePUB/Short story collections and extras/The Road to Dune (Companion book) - Frank Herbert et al.epub"}} \ No newline at end of file diff --git a/lib/library.py b/lib/library.py index 6b4f642..26ddec0 100755 --- a/lib/library.py +++ b/lib/library.py @@ -3,12 +3,13 @@ import json import os import re import zipfile -# import sys -# sys.path.insert(1, '../') -from lib.storage import Storage + from bs4 import BeautifulSoup +from PIL import Image + +from api_hooks import DuckDuckGo from config import Config -from lib.api_hooks import DuckDuckGo +from storage import Storage config = Config() @@ -21,46 +22,40 @@ class Catalogue: self.opf_regx = re.compile(r'\.opf') self.cover_regx = re.compile(r'\.jpg|\.jpeg|\.png|\.bmp|\.gif') self.html_regx = re.compile(r'\.html') - self.scan_folder() 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() + '/') + _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) - regx = re.compile(r"\.epub") - self.books = list(filter(regx.search, filter(None, self.file_list))) def scan_book(self, book): """REMOVE ME?""" _epub = zipfile.ZipFile(book) with _epub as _epub_open: - try: - _epub_open.open('content.opf') - return True - except Exception as e: - print(e) - return False + try: _epub_open.open('content.opf'); return True + except Exception as e: print(e); return False - def filter_books(self, ret=0): + def filter_books(self): """ - Scan book folder recursively for epub files - filter_books(0) -> Catalogue.books - filter_books(1) -> self.books[] - :param ret: 0 -> create class property -> dump json - :param ret: 1 -> create & return class property + Scan book folder recursively for epub files + filter_books(0) -> Catalogue.books + filter_books(1) -> self.books[] + :param ret: 0 -> create class property -> dump json + :param ret: 1 -> create & return class property """ + self.scan_folder() + regx = re.compile(r"\.epub") + self.books = list(filter(regx.search, filter(None, self.file_list))) _book_list_expanded = {} with open(config.book_shelf, 'w') as f: for book in self.books: _book_list_expanded[book] = self.process_book(book) - if ret != 0: return _book_list_expanded - else: - json.dump(_book_list_expanded, f) - return _book_list_expanded + json.dump(_book_list_expanded, f) + return _book_list_expanded def process_book(self, book): """Return dictionary of epub file contents""" @@ -92,12 +87,10 @@ class Catalogue: title = soup.find("dc:title") if title == None: title = book['path'].split('/')[-1].rsplit('.', 1)[0] - else: - title = title.contents[0] + else: title = title.contents[0] author = soup.find("dc:creator") if author != None: author = author.contents[0] - try: - cover = self.extract_cover_image(book_zip, book) + try: cover = self.extract_cover_image(book_zip, book) except IndexError: # cover = self.extract_cover_html(book_zip, book) cover = DuckDuckGo().image_result(title) @@ -106,32 +99,44 @@ class Catalogue: def extract_content(self, book_zip, book): content = book_zip.open( - list(filter(self.opf_regx.search, book['files']))[0]) + list( + filter(self.opf_regx.search, book['files']) + )[0] + ) return content def extract_cover_html(self, book_zip, book): cover = book_zip.open( - list(filter(self.html_regx.search, book['files']))[0]) + list( + filter(self.html_regx.search, book['files']) + )[0] + ) return cover def extract_cover_image(self, book_zip, book): - # TODO Handle books that have no Cover Image - # TODO Handle books with html covers cover = book_zip.open( - list(filter(self.cover_regx.search, book['files']))[0]) - try: - cover = book_zip.read(cover.name) - return cover - except KeyError: - return False + list( + filter(self.cover_regx.search, book['files']) + )[0] + ) + try: cover = book_zip.read(cover.name); return cover + except KeyError: return False - def new_files(self): - storage = Storage() + def compare_shelf_current(self): + stored_books = Storage() + stored_books = stored_books.book_paths_list() try: - a = [] - stored = storage.book_paths_list() - for i in stored: a.append(i[-1]) - unique = set(self.books) - set(a) - return unique + self.books except Exception: - return False + self.filter_books() + unique = set(self.books) - set(stored_books) + return unique + + def import_books(self, list=None): + book_list = self.compare_shelf_current() + db = Storage() + for book in book_list: + book = self.process_book(book) + extracted = self.extract_metadata(book) + db.insert_book(extracted) + db.commit() diff --git a/lib/pyShelf.py b/lib/pyShelf.py index a5d7c2e..abb4d5c 100755 --- a/lib/pyShelf.py +++ b/lib/pyShelf.py @@ -22,22 +22,3 @@ class InitFiles: os.mkdir(os.path.split(_pointer)[0]) f = open(_pointer, "w+") f.close() - - -class Epub: - """All Epub file handling""" - def __init__(self): - global config - self.book_path = config.book_path - self.Catalogue = Catalogue() - - def import_books(self, list=None): - if list is not None: book_list = list - else: book_list = self.Catalogue.filter_books() - for book in book_list: - extracted = self.Catalogue.extract_metadata(book_list[book]) - Storage.insert_book(extracted) - Storage.commit() - - def book_list(self): - pass diff --git a/main.py b/main.py index b5cdc69..6b21013 100755 --- a/main.py +++ b/main.py @@ -1,19 +1,16 @@ #!/usr/bin/python import sys sys.path.insert(1, 'lib/') -from pyShelf import InitFiles, Epub +from pyShelf import InitFiles from config import Config from library import Catalogue config = Config() # Get configuration settings InitFiles(config.file_array) # Initialize file system Catalogue = Catalogue() # Open the Catalogue -# This only needs to be run on first run, & when new books are added -new_books = Catalogue.new_files() -Epub().import_books(new_books) # Filter Your books -# TODO Implement file tracking system to avoid processing already tracked books +# new_books = Catalogue.new_files() +Catalogue.import_books() # Filter Your books # TODO Figure out a system to get books page count -# TODO Update testing # TODO Update Documentation # TODO Requirements.txt # TODO Test image storage diff --git a/tests/__pycache__/test_library.cpython-37.pyc b/tests/__pycache__/test_library.cpython-37.pyc index ac1de5e716636e67cf7eddb72698989a78ac038c..645740847fe777ba67937d55216c3c72d9d6fb6c 100644 GIT binary patch delta 20 acmey*{-2%OiIAShA7(3o`&f5e9bv diff --git a/tests/__pycache__/test_sysio.cpython-37.pyc b/tests/__pycache__/test_sysio.cpython-37.pyc index e7f67963bac4d2a86369d5dc907ce583b6dcbb6a..e2b86f7f916833d3195631ea6ab6cf281bd1d8e5 100644 GIT binary patch delta 51 zcmdnazMY-hiIaU}C&AIfZFDi!e}Ras#u-WMO7wM*hj}%=(NXlgpVM E04f>_L;wH) delta 51 zcmdnazMY-hiIOWjC_;bne`ckCzmrj F002D*3#kAA From 69679b052e3201521f3f32566927f423431f4f10 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 25 Oct 2019 21:43:20 -0400 Subject: [PATCH 4/7] Updated Todos --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 6b21013..ff1d84c 100755 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ InitFiles(config.file_array) # Initialize file system Catalogue = Catalogue() # Open the Catalogue # new_books = Catalogue.new_files() Catalogue.import_books() # Filter Your books +# TODO Resolve database locking after querying for book list # TODO Figure out a system to get books page count # TODO Update Documentation # TODO Requirements.txt -# TODO Test image storage From bba73ea1a7c5e9f2df17a99a4c9866cebe64f2e6 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 25 Oct 2019 21:45:20 -0400 Subject: [PATCH 5/7] Added close method, and finished compare_shelf_current --- lib/library.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/library.py b/lib/library.py index 26ddec0..79c78f1 100755 --- a/lib/library.py +++ b/lib/library.py @@ -123,14 +123,17 @@ class Catalogue: except KeyError: return False def compare_shelf_current(self): - stored_books = Storage() - stored_books = stored_books.book_paths_list() - try: - self.books - except Exception: - self.filter_books() - unique = set(self.books) - set(stored_books) - return unique + db = Storage() + stored = db.book_paths_list() + closed = db.close() + try: self.books + except Exception: self.filter_books() + on_disk, in_storage = [], [] + for _x in self.books: on_disk.append(_x) + for _y in stored: in_storage.append(_y[0]) + a, b, = set(on_disk), set(in_storage) + c = set.difference(a, b) + return c def import_books(self, list=None): book_list = self.compare_shelf_current() @@ -139,4 +142,7 @@ class Catalogue: book = self.process_book(book) extracted = self.extract_metadata(book) db.insert_book(extracted) - db.commit() + inserted = db.commit() + if inserted != True: + print(inserted) + db.close() \ No newline at end of file From 11d89d56d4eed67094751eae2c7248cd4cf0f122 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 25 Oct 2019 21:46:55 -0400 Subject: [PATCH 6/7] implement close method, and return error condition --- lib/storage.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/storage.py b/lib/storage.py index 57d0a25..a5ee801 100644 --- a/lib/storage.py +++ b/lib/storage.py @@ -64,4 +64,8 @@ class Storage: def commit(self): try: self.db.commit(); return True - except Exception as e: return False + except Exception as e: return e + + def close(self): + self.db.close() + return True From f6268904f3d4e3f4d8e1e321bcdc3e967c2a858d Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 31 Oct 2019 14:40:10 -0400 Subject: [PATCH 7/7] Finished checking for new books --- .#config.py | 1 - lib/.#library.py | 1 + lib/library.py | 11 +++++++---- main.py | 10 ++++++---- 4 files changed, 14 insertions(+), 9 deletions(-) delete mode 120000 .#config.py create mode 120000 lib/.#library.py diff --git a/.#config.py b/.#config.py deleted file mode 120000 index a046871..0000000 --- a/.#config.py +++ /dev/null @@ -1 +0,0 @@ -raelon@golumnsec.33289:1571093667 \ No newline at end of file diff --git a/lib/.#library.py b/lib/.#library.py new file mode 120000 index 0000000..9aad06b --- /dev/null +++ b/lib/.#library.py @@ -0,0 +1 @@ +raelon@golumnsec.6371:1572529288 \ No newline at end of file diff --git a/lib/library.py b/lib/library.py index 79c78f1..dde8525 100755 --- a/lib/library.py +++ b/lib/library.py @@ -7,9 +7,9 @@ import zipfile from bs4 import BeautifulSoup from PIL import Image -from api_hooks import DuckDuckGo from config import Config -from storage import Storage +from lib.api_hooks import DuckDuckGo +from lib.storage import Storage config = Config() @@ -17,6 +17,7 @@ config = Config() class Catalogue: """Decodes and stores book information""" """Step One: filter_books""" + def __init__(self): self.file_list = [] self.opf_regx = re.compile(r'\.opf') @@ -143,6 +144,8 @@ class Catalogue: extracted = self.extract_metadata(book) db.insert_book(extracted) inserted = db.commit() - if inserted != True: + if inserted is not True: print(inserted) - db.close() \ No newline at end of file + if input('Continue ? y/n') == 'y': + pass + db.close() diff --git a/main.py b/main.py index ff1d84c..083c060 100755 --- a/main.py +++ b/main.py @@ -1,16 +1,18 @@ #!/usr/bin/python import sys -sys.path.insert(1, 'lib/') -from pyShelf import InitFiles + from config import Config -from library import Catalogue +from lib.library import Catalogue +from lib.pyShelf import InitFiles + +sys.path.insert(1, 'lib/') config = Config() # Get configuration settings InitFiles(config.file_array) # Initialize file system Catalogue = Catalogue() # Open the Catalogue + # new_books = Catalogue.new_files() Catalogue.import_books() # Filter Your books -# TODO Resolve database locking after querying for book list # TODO Figure out a system to get books page count # TODO Update Documentation # TODO Requirements.txt