class BookAuthorModel(database.Model): __tablename__ = 'ass_book_author' fk_tb_book_id = database.Column(database.String(36), database.ForeignKey('tb_book.id_book'), primary_key=True) fk_tb_author_id = database.Column( database.String(36), database.ForeignKey('tb_author.id_author'), primary_key=True) #books = database.relationship("BookModel", back_populates="tb_books") authors = database.relationship("AuthorModel") def __init__(self, book, author): self.fk_tb_book_id = book.id_book self.fk_tb_author_id = author.id_author def find(self): book_author = self.query.filter_by( fk_tb_book_id=self.fk_tb_book_id, fk_tb_author_id=self.fk_tb_author_id).first() return book_author def save(self): database.session.add(self) database.session.commit()
class PersonalInformation(database.Model): __tablename__ = 'personal_information' id = database.Column(database.Integer, primary_key=True) fullname = database.Column(database.String()) avatar = database.Column(database.String()) description = database.Column(database.String()) def __repr__(self): return '<Personal Information {}>'.format(self.fullname)
class Home(database.Model): __tablename__ = 'home' id = database.Column(database.Integer, primary_key=True) welcome = database.Column(database.String(500)) activities = database.Column(database.String(500)) contact = database.Column(database.String(500)) description = database.Column(database.String(500)) def __repr__(self): return '<Home {}>'.format(self.welcome)
class AuthorModel(database.Model): def generate_uuid(): return str(uuid.uuid1()) __tablename__ = 'tb_author' #id = database.Column(database.Integer, primary_key=True) id_author = database.Column(database.String(36), primary_key=True, default=generate_uuid) firstname = database.Column(database.String(20)) middlename = database.Column(database.String(20)) lastname = database.Column(database.String(20)) def __init__(self, firstname, middlename, lastname): self.firstname = firstname self.middlename = middlename self.lastname = lastname def json(self): return { 'id_author': self.id_author, 'firstname': self.firstname, 'middlename': self.middlename, 'lastname': self.lastname, } @classmethod def find(cls, key, field='firstname', like=True): #author = cls.query.filter_by(id_author = id_author).first() if field=='firstname' and like==True: author = cls.query.filter(AuthorModel.firstname.like(f'%{key}%')).first() if field=='id_author': author = cls.query.filter_by(id_author=key).first() if author: return author return None def save(self): database.session.add(self) database.session.commit() def update(self, firstname, middlename, lastname): self.firstname = firstname self.middlename = middlename self.lastname = lastname def delete(self): database.session.delete(self) database.session.commit()
class CredentialModel(database.Model): __tablename__ = 'tb_credential' id_credential = database.Column(database.Integer, primary_key='True') fk_username = database.Column(database.String(36), database.ForeignKey('tb_user.username'), index=True) ev_link = database.Column(database.String(200), nullable=True) ev_email = database.Column(database.String(200), nullable=True) ev_password = database.Column(database.String(200), nullable=True) idx_fk_username = database.Index('idx_fk_username', fk_username) def __init__(self, fk_username, ev_link, ev_email, ev_password): key = b'VnTrZV2i3UfH-VHxKfvXL1NP7gOZyoqBvB0KbQ5sZZ4=' cipher_suite = Fernet(key) ev_email = bytes(ev_email, 'utf-8') ev_password = bytes(ev_password, 'utf-8') self.ev_link = ev_link self.fk_username = fk_username self.ev_email = cipher_suite.encrypt(ev_email) self.ev_password = cipher_suite.encrypt(ev_password) def json(self): return { 'id_credential': self.id_credential, 'username': self.fk_username, 'ev_email' : self.ev_email, 'ev_password' : self.ev_password } @classmethod def find(cls, fk_username): user = cls.query.filter_by(fk_username = fk_username).first() if user: return user return None def save(self): database.session.add(self) database.session.commit() def update(self, fk_username, ev_email, ev_password): self.fk_username = fk_username self.ev_email = ev_email self.ev_password = ev_password def delete(self): database.session.delete(self) database.session.commit()
class Blog(database.Model): __tablename__ = 'blog' id = database.Column(database.Integer, primary_key=True) category = database.Column(database.String(500)) title = database.Column(database.String(500)) content = database.Column(database.String(500)) created_date = database.Column(database.Date) #create new database def __init__ (self, category, title, content): self.category = category self.title = title self.content = content def __repr__(self): return '<Blog {}>'.format(self.category)
class SellerModel(database.Model): __tablename__ = 'seller' __table_args__ = ({"schema": "scraper"}) name = database.Column(database.String(30), primary_key=True) url = database.Column(database.String(200)) store = database.Column(database.String(200)) rating = database.Column(database.Float) ratings = database.Column(database.Float) membersince = database.Column(database.Date) bookamount = database.Column(database.Integer) authentication = database.Column(database.String(20)) def __init__(self, url): self.name = url.replace('https://www.estantevirtual.com.br/livreiros/', '').replace('-', '') self.url = url def json(self): return { "name": self.name, "url": self.url, "store": self.store, "rating": self.rating, "ratings": self.ratings, "membersince": self.membersince, "bookamount": self.bookamount, "authentication": self.authentication } @classmethod def find(cls, url): seller = cls.query.filter_by(url=url).first() if seller: return seller return None def save(self): database.session.add(self) database.session.commit() def update(self, name, url, store, rating, ratings, membersince, bookamount, authentication): self.name = name self.url = url self.store = store self.rating = rating self.ratings = ratings self.membersince = membersince self.bookamount = bookamount self.authentication = authentication def delete(self): database.session.delete(self) database.session.commit()
class EVBookModel(database.Model): #book_author = BooksAuthorsModel() def generate_uuid(self): return str(uuid.uuid1()) __tablename__ = 'tb_estantevirtual' uuid_ev = database.Column(database.String(40), primary_key=True) erro = database.Column(database.String(100)) isbn_issn = database.Column(database.String(100)) autor = database.Column(database.String(200)) titulo = database.Column(database.String(300)) editora = database.Column(database.String(100)) ano = database.Column(database.Integer) estante = database.Column(database.String(100)) preco = database.Column(database.Float) conservacao = database.Column(database.String(8000)) peso = database.Column(database.Float) tipo_publicacao = database.Column(database.String(100)) tipo_produto = database.Column(database.String(100)) edicao_numero = database.Column(database.Integer) numero = database.Column(database.Integer) idioma = database.Column(database.String(100)) volume = database.Column(database.String(100)) acabamento = database.Column(database.String(100)) desconto = database.Column(database.Float) marcas_de_uso = database.Column(database.String(100)) amarelo = database.Column(database.String(100)) manchas_bolor = database.Column(database.String(100)) grifos_anotacoes = database.Column(database.String(100)) amassados_orelha = database.Column(database.String(100)) rasgos = database.Column(database.String(100)) dedicatoria = database.Column(database.String(100)) autografo = database.Column(database.String(100)) numeric_id = database.Column(database.String(100)) assunto = database.Column(database.String(100)) localizacao = database.Column(database.String(100)) seller = database.Column(database.String(100)) def __init__(self, uuid_ev, erro, isbn_issn, autor, titulo, editora, ano, estante, preco, conservacao, peso, tipo_publicacao, tipo_produto, edicao_numero, numero, idioma, volume, acabamento, desconto, marcas_de_uso, amarelo, manchas_bolor, grifos_anotacoes, amassados_orelha, rasgos, dedicatoria, autografo, numeric_id, assunto, localizacao, seller): self.uuid_ev = uuid_ev self.erro = erro self.isbn_issn = isbn_issn self.autor = autor self.titulo = titulo self.editora = editora self.ano = ano self.estante = estante self.preco = preco self.conservacao = conservacao self.peso = peso self.tipo_publicacao = tipo_publicacao self.tipo_produto = tipo_produto self.edicao_numero = edicao_numero self.numero = numero self.idioma = idioma self.volume = volume self.acabamento = acabamento self.desconto = desconto self.marcas_de_uso = marcas_de_uso self.amarelo = amarelo self.manchas_bolor = manchas_bolor self.grifos_anotacoes = grifos_anotacoes self.amassados_orelha = amassados_orelha self.rasgos = rasgos self.dedicatoria = dedicatoria self.autografo = autografo self.numeric_id = numeric_id self.assunto = assunto self.localizacao = localizacao self.seller = seller def json(self): return { "uuid_ev": self.uuid_ev, "erro": self.erro, "isbn_issn": self.isbn_issn, "autor": self.autor, "titulo": self.titulo, "editora": self.editora, "ano": self.ano, "estante": self.estante, "preco": self.preco, "conservacao": self.conservacao, "peso": self.peso, "tipo_publicacao": self.tipo_publicacao, "tipo_produto": self.tipo_produto, "edicao_numero": self.edicao_numero, "numero": self.numero, "idioma": self.idioma, "volume": self.volume, "acabamento": self.acabamento, "desconto": self.desconto, "marcas_de_uso": self.marcas_de_uso, "amarelo": self.amarelo, "manchas_bolor": self.manchas_bolor, "grifos_anotacoes": self.grifos_anotacoes, "amassados_orelha": self.amassados_orelha, "rasgos": self.rasgos, "dedicatoria": self.dedicatoria, "autografo": self.autografo, "numeric_id": self.numeric_id, "assunto": self.assunto, "localizacao": self.localizacao, "seller": self.seller } @classmethod def find(cls, key, field='titulo', like=True): #book = cls.query.filter_by(id_book = id_book).first() if field == 'titulo' and like == True: ev = cls.query.filter(EVBookModel.titulo.like(f'%{key}%')).first() if field == 'uuid_ev': ev = cls.query.filter_by(id_book=key).first() if ev: return ev return None def save(self): database.session.add(self) database.session.commit() def update(self, uuid_ev, erro, isbn_issn, auor, titulo, editora, ano, estante, preco, conservacao, peso, tipo_publicacao, tipo_produto, edicao_numero, numero, idioma, volume, acabamento, desconto, marcas_de_uso, amarelo, manchas_bolor, grifos_anotacoes, amassados_orelha, rasgos, dedicatoria, autografo, numeric_id, assunto, localizacao, seller): self.uuid_ev = uuid_ev self.erro = erro self.isbn_issn = isbn_issn self.autor = autor self.titulo = titulo self.editora = editora self.ano = ano self.estante = estante self.preco = preco self.conservacao = conservacao self.peso = peso self.tipo_publicacao = tipo_publicacao self.tipo_produto = tipo_produto self.edicao_numero = edicao_numero self.numero = numero self.idioma = idioma self.volume = volume self.acabamento = acabamento self.desconto = desconto self.marcas_de_uso = marcas_de_uso self.amarelo = amarelo self.manchas_bolor = manchas_bolor self.grifos_anotacoes = grifos_anotacoes self.amassados_orelha = amassados_orelha self.rasgos = rasgos self.dedicatoria = dedicatoria self.autografo = autografo self.numeric_id = numeric_id self.assunto = assunto self.localizacao = localizacao self.seller = seller def delete(self): database.session.delete(self) database.session.commit() return {"mensage": "Book not found"}
class EdtionModel(database.Model): def generate_uuid(): return str(uuid.uuid1()) __tablename__ = 'tb_edtion' #id_edtion = database.Column(database.String(36), primary_key='True') id_edtion = database.Column(database.String(36), name="id_edtion", primary_key=True, default=generate_uuid) isbn = database.Column(database.String(13)) nedtion = database.Column(database.Integer) volume = database.Column(database.Integer) printnumber = database.Column(database.Integer) tome = database.Column(database.String(10)) year = database.Column(database.Integer) length = database.Column(database.Float) width = database.Column(database.Float) height = database.Column(database.Float) pages = database.Column(database.Integer) subject = database.Column(database.String(20)) language = database.Column(database.String(20)) bookbinding = database.Column(database.String(10)) publisher = database.Column(database.String(20)) synopsis = database.Column(database.String(2000)) fk_tb_book_id = database.Column(database.String(36), database.ForeignKey('tb_book.id_book')) #books = database.relationship('BookModel') def __init__(self, isbn, nedtion, volume, printnumber, tome, year, length, width, height, pages, subject, language, bookbinding, publisher, synopsis, fk_tb_book_id): #self.id_edtion = id_edtion self.isbn = isbn self.nedtion = nedtion self.volume = volume self.printnumber = printnumber self.tome = tome self.year = year self.length = length self.width = width self.height = height self.pages = pages self.subject = subject self.language = language self.bookbinding = bookbinding self.publisher = publisher self.synopsis = synopsis self.fk_tb_book_id = fk_tb_book_id def json(self): return { 'id_edtion': self.id_edtion, 'isbn': self.isbn, 'nedtion': self.nedtion, 'volume': self.volume, 'printnumber': self.printnumber, 'tome': self.tome, 'year': self.year, 'length': self.length, 'width': self.width, 'height': self.height, 'pages': self.pages, 'subject': self.subject, 'language': self.language, 'bookbinding': self.bookbinding, 'publisher': self.publisher, 'synopsis': self.synopsis, 'fk_tb_book_id': self.fk_tb_book_id } @classmethod def find(cls, id_edtion): edtion = cls.query.filter_by(id_edtion=id_edtion).first() if edtion: return edtion return None def save(self): database.session.add(self) database.session.commit() def update(self, id_edtion, isbn, nedtion, volume, printnumber, tome, year, length, width, height, pages, subject, language, bookbinding, publisher, synopsis, fk_tb_book_id): self.id_edtion = id_edtion self.isbn = isbn self.nedtion = nedtion self.volume = volume self.printnumber = printnumber self.tome = tome self.year = year self.length = length self.width = width self.height = height self.pages = pages self.subject = subject self.language = language self.bookbinding = bookbinding self.publisher = publisher self.synopsis = synopsis self.fk_tb_book_id = fk_tb_book_id def delete(self): database.session.delete(self) database.session.commit()