diff --git a/README.md b/README.md index 6544847..3590dc4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # pyShelf A simple terminal based ebook server -Frusterated with Calibre being my only option for hosting my eBook collection, I have decided to spin up my own. +Frustrated with Calibre being my only option for hosting my eBook collection, I have decided to spin up my own. Calibre is a great organizational tool for your books, however not having a terminal based option for running and maintaining a server is cumbersome when running on older equipment. Thus I am creating pyShelf and I hope to be able to provide all diff --git a/__pycache__/config.cpython-37.pyc b/__pycache__/config.cpython-37.pyc old mode 100755 new mode 100644 index e08c325..c3590a7 Binary files a/__pycache__/config.cpython-37.pyc and b/__pycache__/config.cpython-37.pyc differ diff --git a/__pycache__/library.cpython-37.pyc b/__pycache__/library.cpython-37.pyc deleted file mode 100644 index a2d2151..0000000 Binary files a/__pycache__/library.cpython-37.pyc and /dev/null differ diff --git a/__pycache__/main.cpython-37.pyc b/__pycache__/main.cpython-37.pyc deleted file mode 100755 index 07efeb4..0000000 Binary files a/__pycache__/main.cpython-37.pyc and /dev/null differ diff --git a/__pycache__/pyShelf.cpython-37.pyc b/__pycache__/pyShelf.cpython-37.pyc deleted file mode 100755 index c06098d..0000000 Binary files a/__pycache__/pyShelf.cpython-37.pyc and /dev/null differ diff --git a/config.py b/config.py index 0ebcdcb..724906e 100755 --- a/config.py +++ b/config.py @@ -3,9 +3,11 @@ class Config: def __init__(self): self.book_path = "books/" self.book_shelf = "data/shelf.json" + self.catalogue_db = "data/catalogue.db" self.file_array = [ "data/catalogue.json", - "data/shelf.json", + self.book_shelf, + self.catalogue_db, "conf/settings.json" ] self.auto_scan = True \ No newline at end of file diff --git a/data/catalogue.db b/data/catalogue.db new file mode 100644 index 0000000..181a078 Binary files /dev/null and b/data/catalogue.db differ diff --git a/data/shelf.json b/data/shelf.json index f8a2eac..5efa207 100644 --- a/data/shelf.json +++ b/data/shelf.json @@ -1,144 +1 @@ -{ - "/home/raelon/Projects/pyShelf/books/Python Tricks by Dan Bader.epub": { - "files": [ - "content.opf", - "media/cover-6x9.png", - "cover.xhtml" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - }, - "/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" - ] - } -} \ 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/__init__.py b/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/library.py b/lib/library.py new file mode 100755 index 0000000..fda0bac --- /dev/null +++ b/lib/library.py @@ -0,0 +1,96 @@ +#!/usr/bin/python +import json +import os +import re +import zipfile +from bs4 import BeautifulSoup +from config import Config +config = Config() + + +class Catalogue: + """Decodes and stores book information""" + """Step One: filter_books""" + def __init__(self): + self.file_list = [] + 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): + _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 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 + + 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 + """ + 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) + json.dump(_book_list_expanded, f) + return _book_list_expanded + + def process_book(self, book): + """Return dictionary of epub file contents""" + f_name = 'content.opf' + book = zipfile.ZipFile(book, 'r') + details = {} + with book as book_zip: + details['files'] = [] + details['path'] = book.filename + expanded = book_zip.infolist() + regx = re.compile(r'\.opf|cover') + for i in expanded: + match = re.search(regx, i.filename) + if match: + # Returns zip file location of requested files + details['files'].append(match.string) + return details + + def extract_metadata(self, book): + """ + Return extracted metadata and cover picture + book['path'] == Full path to ebook file + book['files'] == list of files from self.process_book(book) + """ + book_zip = zipfile.ZipFile(book['path'], 'r') + opf_regx, cover_regx = re.compile(r'\.opf'), re.compile(r'\.jpg|\.png|\.bmp|\.gif') + with book_zip as f: + content = list(filter(opf_regx.search, book['files'])) + content = book_zip.open(content[0]) + soup = BeautifulSoup(content, "xml") + title = soup.find("dc:title") + author = soup.find("dc:creator") + cover = soup.find("meta", attrs={"name" : "cover"}) + return title + def compare_shelf_current(self): + try: + self.books + except Exception: + self.filter_books() + unique = set(self.books) - set(self.catalogue) + return unique \ No newline at end of file diff --git a/lib/pyShelf.py b/lib/pyShelf.py new file mode 100755 index 0000000..aefeb2a --- /dev/null +++ b/lib/pyShelf.py @@ -0,0 +1,33 @@ +#!/usr/bin/python +import os +import zipfile +from config import Config +config = Config() + +class InitFiles: + """First run file creation operations""" + def __init__(self, file_array): + print("Begining creation of file structure") + for _pointer in file_array: + if not os.path.isfile(_pointer): + self.CreateFile(_pointer) + + def CreateFile(self, _pointer): + """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.close() + + +class Epub: + """All Epub file handling""" + def __init__(self): + global config + self.book_path = config.book_path + + def import_book(self): + pass + + def book_list(self): + pass diff --git a/lib/storage.py b/lib/storage.py new file mode 100644 index 0000000..fdf29a7 --- /dev/null +++ b/lib/storage.py @@ -0,0 +1,48 @@ +#!/usr/bin/python +import sys +import sqlite3 +sys.path.insert(1,'../') +from config import Config +db_pointer = Config().catalogue_db + + +class Storage: + """Contains all methods for system storage""" + + def __init__(self): + self.db_file = db_pointer + self.database() + + def database(self): + """Create database cursor""" + try: + self.db = sqlite3.connect(self.db_file) + self.cursor = self.db.cursor() + return True + except Exception as e: + return False + + def create_tables(self): + """Create table structure""" + q_check = "SELECT * FROM books" + q_create = '''CREATE TABLE books(title text, author text, + categories text, cover blob, pages int, progress int, + file_name text)''' + try: + self.cursor.execute(q_check) + except Exception as e: + self.cursor.execute(q_create) + + def insert_book(self, book): + """ + Insert book in database + :returns: True if succeeds False if not + """ + q = '''INSERT INTO books (title, author, categories, cover, + pages, progress, file_name) values (%s, %s, %s, %s, 0, %s)''' % () + try: + self.cursor.execute(q) + return True + except Exception as e: + print(e) + return False \ No newline at end of file diff --git a/main.py b/main.py index a437626..a2cd878 100755 --- a/main.py +++ b/main.py @@ -1,5 +1,7 @@ #!/usr/bin/python # import zipfile as Zip +import sys +sys.path.insert(1, 'lib/') from pyShelf import InitFiles from config import Config from library import Catalogue @@ -11,5 +13,7 @@ InitFiles(config.file_array) Catalogue = Catalogue() # Filter Your books # This only needs to be run on first run, & when new books are added -book_list = Catalogue.filter_books(0) - +book_list = Catalogue.filter_books() +for book in book_list: + extracted = Catalogue.extract_metadata(book_list[book]) + print(extracted) \ No newline at end of file diff --git a/tests/__pycache__/test_library.cpython-37.pyc b/tests/__pycache__/test_library.cpython-37.pyc index f11933c..3a54b6d 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/__pycache__/test_sysio.cpython-37.pyc b/tests/__pycache__/test_sysio.cpython-37.pyc old mode 100755 new mode 100644 index ab8ae3b..e54ebc1 Binary files a/tests/__pycache__/test_sysio.cpython-37.pyc and b/tests/__pycache__/test_sysio.cpython-37.pyc differ diff --git a/tests/test_library.py b/tests/test_library.py index 61eb1bc..a6b9be7 100755 --- a/tests/test_library.py +++ b/tests/test_library.py @@ -1,14 +1,16 @@ import unittest +import sys +sys.path.insert(1, 'lib/') from library import Catalogue -class Testing(unittest.TestCase): +class LibraryTest(unittest.TestCase): def test_libray_catalogue(self): self.assertIsNotNone(Catalogue()) def test_library_catalogue_filter_books(self): - self.assertIsNotNone(Catalogue().filter_books(1)) + self.assertIsNotNone(Catalogue().filter_books()) if __name__ == '__main__': unittest.main() diff --git a/tests/test_storage.py b/tests/test_storage.py new file mode 100644 index 0000000..48e632c --- /dev/null +++ b/tests/test_storage.py @@ -0,0 +1,16 @@ +import unittest +import sys +sys.path.insert(1, 'lib/') +from storage import Storage + +storage = Storage() + +class StorageTest(unittest.TestCase): + + def test_Storage_databasee(self): + self.assertTrue(storage.database()) + + def test_Storage_create_tables(self): + self.assertIsNot(storage.create_tables(), Exception) +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/tests/test_sysio.py b/tests/test_sysio.py index 39cf27f..b245522 100755 --- a/tests/test_sysio.py +++ b/tests/test_sysio.py @@ -1,6 +1,8 @@ import unittest import os import shutil +import sys +sys.path.insert(1, 'lib/') from pyShelf import InitFiles from pyShelf import Epub