mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Added documentation, & began scan_book method
This commit is contained in:
Binary file not shown.
21
library.py
21
library.py
@@ -2,12 +2,14 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import zipfile
|
||||||
from config import Config
|
from config import Config
|
||||||
config = Config()
|
config = Config()
|
||||||
|
|
||||||
|
|
||||||
class Catalogue:
|
class Catalogue:
|
||||||
"""Decodes and stores book information"""
|
"""Decodes and stores book information"""
|
||||||
|
"""Step One: filter_books"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.file_list = []
|
self.file_list = []
|
||||||
with open(config.book_shelf, 'r') as f:
|
with open(config.book_shelf, 'r') as f:
|
||||||
@@ -26,7 +28,19 @@ class Catalogue:
|
|||||||
self.file_list.append(self.scan_folder(_path))
|
self.file_list.append(self.scan_folder(_path))
|
||||||
self.file_list.append(_path)
|
self.file_list.append(_path)
|
||||||
|
|
||||||
|
def scan_book(self, book):
|
||||||
|
_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, ret=0):
|
def filter_books(self, ret=0):
|
||||||
|
"""
|
||||||
|
filter_books(0) -> Catalogue.books
|
||||||
|
filter_books(1) -> self.books[]
|
||||||
|
:param ret: 0 -> create class property
|
||||||
|
:param ret: 1 -> create & return class property
|
||||||
|
"""
|
||||||
self.scan_folder()
|
self.scan_folder()
|
||||||
regx = re.compile(r"\.epub")
|
regx = re.compile(r"\.epub")
|
||||||
self.books = list(filter(regx.search, filter(None, self.file_list)))
|
self.books = list(filter(regx.search, filter(None, self.file_list)))
|
||||||
@@ -36,6 +50,13 @@ class Catalogue:
|
|||||||
else:
|
else:
|
||||||
return self.books
|
return self.books
|
||||||
|
|
||||||
|
def filter_tags(self, book):
|
||||||
|
f_name = 'content.opf'
|
||||||
|
try:
|
||||||
|
content_opf = list(filter(re.search, book))
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
def compare_shelf_current(self):
|
def compare_shelf_current(self):
|
||||||
try:
|
try:
|
||||||
self.books
|
self.books
|
||||||
|
|||||||
Reference in New Issue
Block a user