working on meta data storage

This commit is contained in:
Raelon Masters
2020-06-14 19:42:49 -04:00
parent 76b631a5a4
commit e3ea56c216
2 changed files with 45 additions and 20 deletions

View File

@@ -115,26 +115,37 @@ class Catalogue:
except IndexError: except IndexError:
# cover = self.extract_cover_html(book_zip, book) # cover = self.extract_cover_html(book_zip, book)
cover = DuckDuckGo().image_result(title) cover = DuckDuckGo().image_result(title)
try: description = self.stripTags(soup.find("dc:description").text) try:
except AttributeError: description = None description = self.stripTags(soup.find("dc:description").text)
try: identifier = self.stripTags(soup.find("dc:identifier").text) except AttributeError:
except AttributeError: identifier = None description = None
try: publisher = self.stripTags(soup.find("dc:publisher").text) try:
except AttributeError: publisher = None identifier = self.stripTags(soup.find("dc:identifier").text)
try: date = self.stripTags(soup.find("dc:date").text) except AttributeError:
except AttributeError: date = None identifier = None
try: rights = self.stripTags(soup.find("dc:rights").text) try:
except AttributeError: rights = None publisher = self.stripTags(soup.find("dc:publisher").text)
try: tags = self.stripTags(soup.find_all("dc:subject").text) except AttributeError:
except AttributeError: tags = None publisher = None
try:
date = self.stripTags(soup.find("dc:date").text)
except AttributeError:
date = None
try:
rights = self.stripTags(soup.find("dc:rights").text)
except AttributeError:
rights = None
try:
tags = soup.find_all("dc:subject")
except AttributeError:
tags = None
ftags = None ftags = None
breakpoint()
if tags is not None: if tags is not None:
for tag in tags: for tag in tags:
if ftags is None: if ftags is None:
ftags = tag ftags = tag.text
else: else:
ftags = ftags+","+tag ftags = ftags + "," + tag.text
book_details = [ book_details = [
title, title,
author, author,
@@ -145,14 +156,14 @@ class Catalogue:
publisher, publisher,
date, date,
rights, rights,
ftags ftags,
] ]
return book_details return book_details
@staticmethod @staticmethod
def stripTags(source): def stripTags(source):
p = re.compile(r'<.*?>') p = re.compile(r"<.*?>")
return p.sub('', source) return p.sub("", source)
@staticmethod @staticmethod
def extract_metadata_mobi(book): def extract_metadata_mobi(book):

View File

@@ -53,7 +53,7 @@ class Storage:
Insert book in database Insert book in database
:returns: True if succeeds False if not :returns: True if succeeds False if not
""" """
q = "INSERT INTO books (title, author, cover, progress, file_name, pages) values (%s, %s, %s, 0, %s, 0);" q = "INSERT INTO books (title, author, cover, progress, file_name, pages, description, publisher, date, rights, tags) values (%s, %s, %s, 0, %s, 0, %s, %s, %s, %s, %s);"
try: try:
try: try:
cover_image = book[2].data cover_image = book[2].data
@@ -61,7 +61,21 @@ class Storage:
cover_image = book[2] cover_image = book[2]
if not book[2]: # If cover image is missing unset entry if not book[2]: # If cover image is missing unset entry
cover_image = None cover_image = None
self.cursor.execute(q, (book[0], book[1], cover_image, book[3])) self.cursor.execute(
q,
(
book[0],
book[1],
cover_image,
book[3],
book[4],
book[5],
book[6],
book[7],
book[8],
book[9],
),
)
return True return True
except Exception as e: except Exception as e:
print(e) print(e)