diff --git a/.gitignore b/.gitignore index b4faaa0..bf8ad81 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ books/* *.json *.pyc content.opf +.vscode/.editorconfig diff --git a/.vscode/settings.json b/.vscode/settings.json index ec1cf14..7be0ae1 100755 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,5 +9,5 @@ "python.testing.pytestEnabled": false, "python.testing.nosetestsEnabled": false, "python.testing.unittestEnabled": true, - "python.pythonPath": "/home/raelon/.virtualenvs/spyder/bin/python" + "python.pythonPath": "/home/raelon/.virtualenvs/pyShelf/bin/python" } \ No newline at end of file diff --git a/lib/library.py b/lib/library.py index fda0bac..74fe277 100755 --- a/lib/library.py +++ b/lib/library.py @@ -3,6 +3,7 @@ import json import os import re import zipfile +from PIL import Image from bs4 import BeautifulSoup from config import Config config = Config() @@ -78,19 +79,20 @@ class Catalogue: 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') + opf_regx, cover_regx = re.compile(r'\.opf'), re.compile(r'\.jpg|\.jpeg|\.png|\.bmp|\.gif') with book_zip as f: - content = list(filter(opf_regx.search, book['files'])) - content = book_zip.open(content[0]) + content = book_zip.open(list(filter(opf_regx.search, book['files']))[0]) + cover = book_zip.open(list(filter(cover_regx.search, book['files']))[0]) soup = BeautifulSoup(content, "xml") title = soup.find("dc:title") author = soup.find("dc:creator") - cover = soup.find("meta", attrs={"name" : "cover"}) - return title + book_details = [title.contents[0], author.contents[0], cover] + return book_details + 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 + return unique