|
|
|
import os
|
|
|
|
|
|
|
|
import marshmallow
|
|
|
|
import sqlalchemy
|
|
|
|
import sqlalchemy.orm
|
|
|
|
import sqlalchemy.ext.declarative
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
DB_PATH = os.path.expandvars('$HOME/quotes/quotes.db')
|
|
|
|
|
|
|
|
engine = sqlalchemy.create_engine(f'sqlite:///{DB_PATH}')
|
|
|
|
Session = sqlalchemy.orm.sessionmaker(bind=engine)
|
|
|
|
Base = sqlalchemy.ext.declarative.declarative_base()
|
|
|
|
|
|
|
|
|
|
|
|
class Quote(Base):
|
|
|
|
|
|
|
|
__tablename__ = 'quotes'
|
|
|
|
|
|
|
|
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
|
|
|
|
video_id = sqlalchemy.Column(sqlalchemy.Integer)
|
|
|
|
date = sqlalchemy.Column(sqlalchemy.Date)
|
|
|
|
game = sqlalchemy.Column(sqlalchemy.String)
|
|
|
|
text = sqlalchemy.Column(sqlalchemy.String)
|
|
|
|
created_at = sqlalchemy.Column(sqlalchemy.DateTime)
|
|
|
|
updated_at = sqlalchemy.Column(sqlalchemy.DateTime)
|
|
|
|
|
|
|
|
def __init__(self, id, video_id, date, game, text):
|
|
|
|
self.id = id
|
|
|
|
self.video_id = video_id
|
|
|
|
self.date = date
|
|
|
|
self.game = game
|
|
|
|
self.text = text
|
|
|
|
self.created_at = datetime.now()
|
|
|
|
self.updated_at = datetime.now()
|
|
|
|
|
|
|
|
|
|
|
|
class QuoteSchema(marshmallow.Schema):
|
|
|
|
|
|
|
|
id = marshmallow.fields.Integer()
|
|
|
|
video_id = marshmallow.fields.Integer()
|
|
|
|
date = marshmallow.fields.Date()
|
|
|
|
game = marshmallow.fields.Str()
|
|
|
|
text = marshmallow.fields.Str()
|
|
|
|
created_at = marshmallow.fields.DateTime()
|
|
|
|
updated_at = marshmallow.fields.DateTime()
|