From 27f1e07af857d9fed0b2a401fd779bf013d82f88 Mon Sep 17 00:00:00 2001 From: Hemant Sachdeva Date: Wed, 20 Oct 2021 17:28:20 +0530 Subject: [PATCH] treewide: Code quality improvement Signed-off-by: Hemant Sachdeva --- src/main.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.py b/src/main.py index 14171bd..81c6421 100644 --- a/src/main.py +++ b/src/main.py @@ -27,16 +27,16 @@ @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'POST': - cat = request.form.getlist('catagory') - if cat: - cat = ','.join(cat) # making cat list a ',' separated string - url = "https://v2.jokeapi.dev/joke/{}".format(cat) - else: - url = "https://v2.jokeapi.dev/joke/Any" - flag = request.form.getlist('flag') - if flag: - flag = ','.join(flag) # making flag list a ',' separated string - url += '?blacklistFlags={}'.format(flag) + joke_category = request.form.getlist('catagory') + # set joke category to Any if no category chosen, make ',' separated string otherwise + joke_category = 'Any' if len(joke_category) == 0 else ','.join(joke_category) + url = "https://v2.jokeapi.dev/joke/{}".format(joke_category) + + blacklist_joke = request.form.getlist('flag') + if len(blacklist_joke) != 0: + # making flag list a ',' separated string if multiple blacklists chosen + blacklist_joke = ','.join(blacklist_joke) + url += '?blacklistFlags={}'.format(blacklist_joke) resp = requests.get(url) data = resp.json() if data.get('type') == 'single':