diff --git a/.ipynb_checkpoints/scratchpad-checkpoint.ipynb b/.ipynb_checkpoints/scratchpad-checkpoint.ipynb index edcdb4f..b6061a6 100644 --- a/.ipynb_checkpoints/scratchpad-checkpoint.ipynb +++ b/.ipynb_checkpoints/scratchpad-checkpoint.ipynb @@ -2,91 +2,39 @@ "cells": [ { "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [], - "source": [ - "from library import Catalogue\n", - "import zipfile\n", - "\n", - "Catalogue = Catalogue()\n", - "book_list = Catalogue.filter_books(1)\n", - "unpacked = []" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [ - { - "ename": "SyntaxError", - "evalue": "invalid syntax (, line 4)", - "output_type": "error", - "traceback": [ - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m4\u001b[0m\n\u001b[0;31m book.\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" - ] - } - ], - "source": [ - "for book in book_list:\n", - " book = zipfile.ZipFile(book, 'r')\n", - " with book as bookzip:\n", - " book." - ] - }, - { - "cell_type": "code", - "execution_count": 23, + "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ + "\n", "\n" ] - }, - { - "ename": "KeyError", - "evalue": "\"There is no item named 'content.opf' in the archive\"", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0munpacked\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mbookzip\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mdetails\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mbookzip\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'content.opf'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdetails\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/lib64/python3.7/zipfile.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(self, name, mode, pwd, force_zip64)\u001b[0m\n\u001b[1;32m 1468\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1469\u001b[0m \u001b[0;31m# Get info object for name\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1470\u001b[0;31m \u001b[0mzinfo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetinfo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1471\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1472\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mmode\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'w'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/lib64/python3.7/zipfile.py\u001b[0m in \u001b[0;36mgetinfo\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 1396\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0minfo\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1397\u001b[0m raise KeyError(\n\u001b[0;32m-> 1398\u001b[0;31m 'There is no item named %r in the archive' % name)\n\u001b[0m\u001b[1;32m 1399\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1400\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0minfo\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mKeyError\u001b[0m: \"There is no item named 'content.opf' in the archive\"" - ] } ], "source": [ - "for i in unpacked:\n", - " with i as bookzip:\n", - " details = bookzip.open('content.opf')\n", - " print(details)" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "'ZipFile' object is not subscriptable", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mbookzip\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m: 'ZipFile' object is not subscriptable" - ] - } - ], - "source": [ - "bookzip" + "from library import Catalogue\n", + "import zipfile\n", + "import pprint as pp\n", + "import re\n", + "\n", + "Catalogue = Catalogue()\n", + "book_list = Catalogue.filter_books(1)\n", + "unpacked = []\n", + "\n", + "for book in book_list:\n", + " book = zipfile.ZipFile(book, 'r')\n", + " with book as bookzip:\n", + " try:\n", + " content_opf = bookzip.open('content.opf')\n", + " print(content_opf)\n", + " except KeyError as e:\n", + " expanded = bookzip.infolist()\n", + " regx1 = re.compile(r'\\.opf|^cover')\n", + " for i in expanded:\n", + " if re.search(regx1, str(i)) == True: pp.pprint(i.filename); print(res)" ] }, { diff --git a/.vscode/settings.json b/.vscode/settings.json index 66bfd50..ec1cf14 100755 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,5 +8,6 @@ ], "python.testing.pytestEnabled": false, "python.testing.nosetestsEnabled": false, - "python.testing.unittestEnabled": true + "python.testing.unittestEnabled": true, + "python.pythonPath": "/home/raelon/.virtualenvs/spyder/bin/python" } \ No newline at end of file diff --git a/__pycache__/library.cpython-37.pyc b/__pycache__/library.cpython-37.pyc index e712bf9..a2d2151 100644 Binary files a/__pycache__/library.cpython-37.pyc and b/__pycache__/library.cpython-37.pyc differ diff --git a/data/shelf.json b/data/shelf.json index fd9e325..f8a2eac 100644 --- a/data/shelf.json +++ b/data/shelf.json @@ -1 +1,144 @@ -["/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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", "/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"] \ 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" + ] + }, + "/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 diff --git a/library.py b/library.py index 84f84d2..657d402 100755 --- a/library.py +++ b/library.py @@ -44,18 +44,29 @@ class Catalogue: self.scan_folder() regx = re.compile(r"\.epub") self.books = list(filter(regx.search, filter(None, self.file_list))) + _book_list_expanded = {} if ret == 0: with open(config.book_shelf, 'w') as f: - json.dump(self.books, f) + for book in self.books: + _book_list_expanded[book] = self.process_book(book) + json.dump(_book_list_expanded, f) else: return self.books - def filter_tags(self, book): + def process_book(self, book): f_name = 'content.opf' - try: - content_opf = list(filter(re.search, book)) - except: - return False + book = zipfile.ZipFile(book, 'r') + details = {} + with book as book_zip: + details['files'] = [] + 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 compare_shelf_current(self): try: diff --git a/main.py b/main.py index 19887e3..a437626 100755 --- a/main.py +++ b/main.py @@ -3,9 +3,13 @@ from pyShelf import InitFiles from config import Config from library import Catalogue - +# Get configuration settings config = Config() - +# Initialize file system InitFiles(config.file_array) +# Open the Catalogue Catalogue = Catalogue() -book_list = Catalogue.filter_books(1) +# Filter Your books +# This only needs to be run on first run, & when new books are added +book_list = Catalogue.filter_books(0) + diff --git a/scratchpad.ipynb b/scratchpad.ipynb index 53d3da9..b6061a6 100644 --- a/scratchpad.ipynb +++ b/scratchpad.ipynb @@ -2,35 +2,23 @@ "cells": [ { "cell_type": "code", - "execution_count": 21, + "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n", "\n", - "\n" - ] - }, - { - "ename": "KeyError", - "evalue": "\"There is no item named 'content.opf' in the archive\"", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mbook\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mbookzip\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbookzip\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbookzip\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'content.opf'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m/usr/lib64/python3.7/zipfile.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(self, name, mode, pwd, force_zip64)\u001b[0m\n\u001b[1;32m 1468\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1469\u001b[0m \u001b[0;31m# Get info object for name\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1470\u001b[0;31m \u001b[0mzinfo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetinfo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1471\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1472\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mmode\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'w'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/lib64/python3.7/zipfile.py\u001b[0m in \u001b[0;36mgetinfo\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 1396\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0minfo\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1397\u001b[0m raise KeyError(\n\u001b[0;32m-> 1398\u001b[0;31m 'There is no item named %r in the archive' % name)\n\u001b[0m\u001b[1;32m 1399\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1400\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0minfo\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mKeyError\u001b[0m: \"There is no item named 'content.opf' in the archive\"" + "\n" ] } ], "source": [ "from library import Catalogue\n", "import zipfile\n", + "import pprint as pp\n", + "import re\n", "\n", "Catalogue = Catalogue()\n", "book_list = Catalogue.filter_books(1)\n", @@ -39,8 +27,14 @@ "for book in book_list:\n", " book = zipfile.ZipFile(book, 'r')\n", " with book as bookzip:\n", - " print(bookzip)\n", - " print(bookzip.open('content.opf'))" + " try:\n", + " content_opf = bookzip.open('content.opf')\n", + " print(content_opf)\n", + " except KeyError as e:\n", + " expanded = bookzip.infolist()\n", + " regx1 = re.compile(r'\\.opf|^cover')\n", + " for i in expanded:\n", + " if re.search(regx1, str(i)) == True: pp.pprint(i.filename); print(res)" ] }, { diff --git a/scratchpad.py b/scratchpad.py new file mode 100644 index 0000000..8894cef --- /dev/null +++ b/scratchpad.py @@ -0,0 +1,29 @@ +# To add a new cell, type '#%%' +# To add a new markdown cell, type '#%% [markdown]' +#%% +from library import Catalogue +import zipfile +import pprint as pp +import re + +Catalogue = Catalogue() +book_list = Catalogue.filter_books(1) +unpacked = [] + +for book in book_list: + book = zipfile.ZipFile(book, 'r') + with book as bookzip: + try: + content_opf = bookzip.open('content.opf') + print(content_opf) + except KeyError as e: + expanded = bookzip.infolist() + regx1 = re.compile(r'\.opf|^cover') + for i in expanded: + if re.search(regx1, str(i)) == True: pp.pprint(i.filename); print(res) + + +#%% + + +