From b4b8b352ae11f8258eef5f37fa9b41f771b3c61b Mon Sep 17 00:00:00 2001 From: Anson Date: Thu, 9 Apr 2020 02:48:04 -0700 Subject: [PATCH] added param for more than 1 quote --- quote/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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]}))