precommit formatting

This commit is contained in:
th3r00t
2022-11-14 00:03:50 -05:00
parent 1e4d52bf0a
commit c8a80406e5
2 changed files with 37 additions and 20 deletions

24
src/backend/lib/storage.py vendored Executable file → Normal file
View File

@@ -1,10 +1,11 @@
#!/usr/bin/python
import datetime
import re
from .models import Book, Collection
from sqlalchemy import create_engine, text, select
from sqlalchemy import create_engine, select
from sqlalchemy.orm import Session
from .models import Book, Collection
class Storage:
"""Contains all methods for system storage"""
@@ -15,7 +16,9 @@ class Storage:
self.password = config.password
self.db_host = config.db_host
self.db_port = config.db_port
self.engine = create_engine(f"postgresql://{self.user}:{self.password}@{self.db_host}:{self.db_port}/{self.sql}")
self.engine = create_engine(
f"postgresql://{self.user}:{self.password}@{self.db_host}:{self.db_port}/{self.sql}"
)
self.config = config
def create_tables(self):
@@ -37,7 +40,7 @@ class Storage:
if not book[2]: # If cover image is missing unset entry
cover_image = None
if not book[1]:
author = "None"
pass
_book = Book(
title=book[0],
author=book[1],
@@ -47,7 +50,7 @@ class Storage:
identifier=book[5],
publisher=book[6],
rights=book[8],
tags=book[9]
tags=book[9],
)
session.add(_book)
session.commit()
@@ -68,6 +71,7 @@ class Storage:
def make_collections(self):
# TODO: Check this still works with the switch to sqlalchemy
self.config.logger.info("Making collections.")
_title_regx = re.compile(r"^[0-9][0-9]*|-|\ \B")
session = Session(self.engine)
_set = session.execute(select(Book.book_id, Book.file_name)).all()
@@ -86,7 +90,12 @@ class Storage:
_x = re.sub(_title_regx, "", _s)
_s = _x.strip()
_sess = Session(self.engine)
_q = _sess.execute(select(Collection.collection_id).where(Collection.collection == _s, Collection.book_id == book.book_id))
_q = _sess.execute(
select(Collection.collection_id).where(
Collection.collection == _s,
Collection.book_id == book.book_id,
)
)
_sess.close()
if _q.fetchone() is None:
_collection = Collection(collection=_s, book_id=book.book_id)
@@ -99,3 +108,4 @@ class Storage:
except Exception as e:
self.config.logger.error(f"Collection {_s} failed: {e}")
_collections.append(_p)
self.config.logger.info("Finished making collections.")