Add random, amnesiac method
This commit is contained in:
parent
f91c47571f
commit
9eee22a4e5
@ -3,12 +3,13 @@ from flask_restx import reqparse
|
|||||||
from flask import make_response
|
from flask import make_response
|
||||||
from api.clientGetter import getClientSafely
|
from api.clientGetter import getClientSafely
|
||||||
import logging
|
import logging
|
||||||
|
import random
|
||||||
|
|
||||||
# Exported namespace
|
# Exported namespace
|
||||||
api = Namespace('resource', description='Interact with the raw underlying resource')
|
api = Namespace('resource', description='Interact with the raw underlying files. This namespace does NOT speak json, just raw files')
|
||||||
|
|
||||||
@api.route('/exact/<string:file_name>')
|
@api.route('/exact/<string:file_name>')
|
||||||
@api.doc(description="Returns the raw file. This endpoint expects exact files, NOT json")
|
@api.doc(description="Interact with exact raw files.")
|
||||||
class getExactFile(Resource):
|
class getExactFile(Resource):
|
||||||
@api.doc('get')
|
@api.doc('get')
|
||||||
@api.response(200, 'Sucess')
|
@api.response(200, 'Sucess')
|
||||||
@ -26,3 +27,19 @@ class getExactFile(Resource):
|
|||||||
return {
|
return {
|
||||||
"message": "Requested file '" + file_name + "' not found"
|
"message": "Requested file '" + file_name + "' not found"
|
||||||
}, 404
|
}, 404
|
||||||
|
|
||||||
|
@api.route('/random')
|
||||||
|
@api.doc(description="Returns a random meme")
|
||||||
|
class getRandomFile(Resource):
|
||||||
|
@api.doc('get')
|
||||||
|
@api.response(200, 'Sucess')
|
||||||
|
@api.response(500, 'S3 Error')
|
||||||
|
def get(self):
|
||||||
|
client = getClientSafely()
|
||||||
|
if client is None:
|
||||||
|
return {
|
||||||
|
"message" : "Error connecting to S3"
|
||||||
|
}, 500
|
||||||
|
choice = random.choice(tuple(client.getCurrentMemeList()))
|
||||||
|
return make_response(client.getMeme(choice))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user