From 607a403a8c8925126e9925c9ee34f17dcc9e7e85 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sun, 30 Jun 2024 12:13:46 +0200 Subject: [PATCH] Additional checks, if bf api is not accessible --- cbpi/__init__.py | 2 +- cbpi/controller/upload_controller.py | 41 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 35fff875..b45636ec 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.4.2.a5" +__version__ = "4.4.2.a6" __codename__ = "Yeast Starter" diff --git a/cbpi/controller/upload_controller.py b/cbpi/controller/upload_controller.py index 2567689e..a4d86fde 100644 --- a/cbpi/controller/upload_controller.py +++ b/cbpi/controller/upload_controller.py @@ -101,36 +101,35 @@ async def get_brewfather_recipes(self,offset=0): except Exception as e: logging.error(e) repeat = False - - if bf_recipe_list: - #loop +=1 - for row in bf_recipe_list: - recipe_id = row['_id'] - name = row['name'] - element = {'value': recipe_id, 'label': name} - result.append(element) - else: - repeat = False - - if len(bf_recipe_list) != limit: - #logging.info(loop) - repeat = False - else: - parameters={"limit": limit, 'start_after': recipe_id} - - + try: + if bf_recipe_list: + for row in bf_recipe_list: + recipe_id = row['_id'] + name = row['name'] + element = {'value': recipe_id, 'label': name} + result.append(element) + else: + repeat = False + except Exception as e: + logging.error(e) + try: + if len(bf_recipe_list) != limit: + repeat = False + else: + parameters={"limit": limit, 'start_after': recipe_id} + except Exception as e: + logging.error(e) + try: newlist = sorted(result, key=lambda d: d['label']) listlength=len(newlist) max=math.floor(listlength/length) - #logging.error(listlength) - #logging.error(length) sortlist=[] for i in range(0 , max+1): sortlist.append({ 'value': i*length, 'label': i*length }) - #logging.error(sortlist) return newlist, sortlist, length except: + logging.error("Return empty BF recipe list") sortlist=[{ 'value': 0, 'label': '0' }] return result, sortlist, length