|
|
|
@ -4,49 +4,24 @@ import flask_login
|
|
|
|
|
import flask_restful
|
|
|
|
|
import flask_restful.fields
|
|
|
|
|
import flask_restful.reqparse
|
|
|
|
|
import flask_sqlalchemy
|
|
|
|
|
import itsdangerous
|
|
|
|
|
import sqlalchemy
|
|
|
|
|
|
|
|
|
|
from db import db, Quote
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = flask.Flask(__name__)
|
|
|
|
|
app.config.from_envvar('SETTINGS')
|
|
|
|
|
|
|
|
|
|
db = flask_sqlalchemy.SQLAlchemy(app)
|
|
|
|
|
db.create_all()
|
|
|
|
|
|
|
|
|
|
api = flask_restful.Api(app)
|
|
|
|
|
db.init_app(app)
|
|
|
|
|
db.create_all(app=app)
|
|
|
|
|
|
|
|
|
|
login_manager = flask_login.LoginManager()
|
|
|
|
|
login_manager.init_app(app)
|
|
|
|
|
|
|
|
|
|
flask_cors.CORS(app)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_manager.request_loader
|
|
|
|
|
def load_user(request):
|
|
|
|
|
key = request.headers.get('X-Quotes-API-Key')
|
|
|
|
|
if not key:
|
|
|
|
|
return None
|
|
|
|
|
s = itsdangerous.TimedJSONWebSignatureSerializer(app.config['SECRET_KEY'])
|
|
|
|
|
try:
|
|
|
|
|
user = flask_login.UserMixin()
|
|
|
|
|
user.id = s.loads(key)
|
|
|
|
|
return user
|
|
|
|
|
except (itsdangerous.SignatureExpired, itsdangerous.BadSignature):
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Quote(db.Model):
|
|
|
|
|
__tablename__ = 'quotes'
|
|
|
|
|
api = flask_restful.Api(app)
|
|
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
|
video_id = db.Column(db.Integer)
|
|
|
|
|
date = db.Column(db.Date)
|
|
|
|
|
game = db.Column(db.String)
|
|
|
|
|
text = db.Column(db.String)
|
|
|
|
|
created_at = db.Column(db.DateTime)
|
|
|
|
|
updated_at = db.Column(db.DateTime)
|
|
|
|
|
flask_cors.CORS(app)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
quote_fields = {
|
|
|
|
@ -76,6 +51,20 @@ filter_parser.add_argument('page_number', type=int)
|
|
|
|
|
filter_parser.add_argument('page_size', type=int)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_manager.request_loader
|
|
|
|
|
def load_user(request):
|
|
|
|
|
key = request.headers.get('X-Quotes-API-Key')
|
|
|
|
|
if not key:
|
|
|
|
|
return None
|
|
|
|
|
s = itsdangerous.TimedJSONWebSignatureSerializer(app.config['SECRET_KEY'])
|
|
|
|
|
try:
|
|
|
|
|
user = flask_login.UserMixin()
|
|
|
|
|
user.id = s.loads(key)
|
|
|
|
|
return user
|
|
|
|
|
except (itsdangerous.SignatureExpired, itsdangerous.BadSignature):
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class QuoteResource(flask_restful.Resource):
|
|
|
|
|
@flask_restful.marshal_with(quote_fields)
|
|
|
|
|
def get(self, id):
|
|
|
|
|