diff --git a/quote/__init__.py b/quote/__init__.py index 21130ed..9bab517 100644 --- a/quote/__init__.py +++ b/quote/__init__.py @@ -6,5 +6,16 @@ from . import quotes def main(req: func.HttpRequest) -> func.HttpResponse: + batch = req.params.get("batch") + random.shuffle(quotes.quotes) + if batch is not None: + try: + batch = int(batch) + except ValueError: + return func.HttpResponse( + "'batch' param must be an integer.", status_code=400 + ) + return func.HttpResponse(json.dumps({"quotes": quotes.quotes[0:batch]})) + logging.info("Python HTTP trigger function processed a request.") - return func.HttpResponse(json.dumps({"quote": random.choice(quotes.quotes)})) + return func.HttpResponse(json.dumps({"quote": quotes.quotes[0]}))