From 3bf8a9ba6bb5d1993f5792d50e75b2d52c3caaba Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sun, 23 Jun 2024 14:53:03 +0200 Subject: [PATCH] further change for BF v2 api --- cbpi/__init__.py | 2 +- cbpi/controller/upload_controller.py | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 517bf0f..180fe34 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.4.2.a3" +__version__ = "4.4.2.a4" __codename__ = "Yeast Starter" diff --git a/cbpi/controller/upload_controller.py b/cbpi/controller/upload_controller.py index 6e967ed..2567689 100644 --- a/cbpi/controller/upload_controller.py +++ b/cbpi/controller/upload_controller.py @@ -17,7 +17,7 @@ import os.path from os import listdir from os.path import isfile, join import json -import shortuuid +import math import yaml from ..api.step import StepMove, StepResult, StepState import re @@ -70,7 +70,7 @@ class UploadController: async def get_brewfather_recipes(self,offset=0): limit = 50 - #loop=0 + length = self.cbpi.config.get('brewfather_list_length',50) repeat = True brewfather = True result=[] @@ -91,10 +91,16 @@ class UploadController: try: async with aiohttp.ClientSession(headers=headers) as bf_session: async with bf_session.get(self.url, params=parameters) as r: - bf_recipe_list = await r.json() + if r.status == 429: + logging.error("Too many requests to BF api. Try again later") + self.cbpi.notify("Error", "Too many requests to BF api. Try again later", NotificationType.ERROR) + repeat = False + else: + bf_recipe_list = await r.json() await bf_session.close() except Exception as e: logging.error(e) + repeat = False if bf_recipe_list: #loop +=1 @@ -112,13 +118,21 @@ class UploadController: else: parameters={"limit": limit, 'start_after': recipe_id} - #logging.info(len(result)) + try: newlist = sorted(result, key=lambda d: d['label']) - #logging.info(newlist) - return newlist + 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: - return result + sortlist=[{ 'value': 0, 'label': '0' }] + return result, sortlist, length def get_creation_path(self):