mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-24 07:58:11 +01:00
further change for BF v2 api
This commit is contained in:
parent
0f7308b745
commit
3bf8a9ba6b
2 changed files with 22 additions and 8 deletions
|
@ -1,3 +1,3 @@
|
||||||
__version__ = "4.4.2.a3"
|
__version__ = "4.4.2.a4"
|
||||||
__codename__ = "Yeast Starter"
|
__codename__ = "Yeast Starter"
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import os.path
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from os.path import isfile, join
|
from os.path import isfile, join
|
||||||
import json
|
import json
|
||||||
import shortuuid
|
import math
|
||||||
import yaml
|
import yaml
|
||||||
from ..api.step import StepMove, StepResult, StepState
|
from ..api.step import StepMove, StepResult, StepState
|
||||||
import re
|
import re
|
||||||
|
@ -70,7 +70,7 @@ class UploadController:
|
||||||
|
|
||||||
async def get_brewfather_recipes(self,offset=0):
|
async def get_brewfather_recipes(self,offset=0):
|
||||||
limit = 50
|
limit = 50
|
||||||
#loop=0
|
length = self.cbpi.config.get('brewfather_list_length',50)
|
||||||
repeat = True
|
repeat = True
|
||||||
brewfather = True
|
brewfather = True
|
||||||
result=[]
|
result=[]
|
||||||
|
@ -91,10 +91,16 @@ class UploadController:
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession(headers=headers) as bf_session:
|
async with aiohttp.ClientSession(headers=headers) as bf_session:
|
||||||
async with bf_session.get(self.url, params=parameters) as r:
|
async with bf_session.get(self.url, params=parameters) as r:
|
||||||
|
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()
|
bf_recipe_list = await r.json()
|
||||||
await bf_session.close()
|
await bf_session.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
|
repeat = False
|
||||||
|
|
||||||
if bf_recipe_list:
|
if bf_recipe_list:
|
||||||
#loop +=1
|
#loop +=1
|
||||||
|
@ -112,13 +118,21 @@ class UploadController:
|
||||||
else:
|
else:
|
||||||
parameters={"limit": limit, 'start_after': recipe_id}
|
parameters={"limit": limit, 'start_after': recipe_id}
|
||||||
|
|
||||||
#logging.info(len(result))
|
|
||||||
try:
|
try:
|
||||||
newlist = sorted(result, key=lambda d: d['label'])
|
newlist = sorted(result, key=lambda d: d['label'])
|
||||||
#logging.info(newlist)
|
listlength=len(newlist)
|
||||||
return 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:
|
except:
|
||||||
return result
|
sortlist=[{ 'value': 0, 'label': '0' }]
|
||||||
|
return result, sortlist, length
|
||||||
|
|
||||||
|
|
||||||
def get_creation_path(self):
|
def get_creation_path(self):
|
||||||
|
|
Loading…
Reference in a new issue