mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-21 14:38:15 +01:00
brewfatherapiv2test
This commit is contained in:
parent
eb1365d329
commit
97845bc2dc
2 changed files with 38 additions and 21 deletions
|
@ -1,3 +1,3 @@
|
||||||
__version__ = "4.4.1"
|
__version__ = "4.4.2.a1"
|
||||||
__codename__ = "Yeast Starter"
|
__codename__ = "Yeast Starter"
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ from ..api.step import StepMove, StepResult, StepState
|
||||||
import re
|
import re
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
|
||||||
class UploadController:
|
class UploadController:
|
||||||
|
|
||||||
def __init__(self, cbpi):
|
def __init__(self, cbpi):
|
||||||
|
@ -70,9 +69,12 @@ class UploadController:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
async def get_brewfather_recipes(self,offset=0):
|
async def get_brewfather_recipes(self,offset=0):
|
||||||
|
limit = 50
|
||||||
|
loop=0
|
||||||
|
repeat = True
|
||||||
brewfather = True
|
brewfather = True
|
||||||
result=[]
|
result=[]
|
||||||
self.url="https://api.brewfather.app/v1/recipes"
|
self.url="https://api.brewfather.app/v2/recipes"
|
||||||
brewfather_user_id = self.cbpi.config.get("brewfather_user_id", None)
|
brewfather_user_id = self.cbpi.config.get("brewfather_user_id", None)
|
||||||
if brewfather_user_id == "" or brewfather_user_id is None:
|
if brewfather_user_id == "" or brewfather_user_id is None:
|
||||||
brewfather = False
|
brewfather = False
|
||||||
|
@ -84,25 +86,40 @@ class UploadController:
|
||||||
if brewfather == True:
|
if brewfather == True:
|
||||||
encodedData = base64.b64encode(bytes(f"{brewfather_user_id}:{brewfather_api_key}", "ISO-8859-1")).decode("ascii")
|
encodedData = base64.b64encode(bytes(f"{brewfather_user_id}:{brewfather_api_key}", "ISO-8859-1")).decode("ascii")
|
||||||
headers={"Authorization": "Basic %s" % encodedData}
|
headers={"Authorization": "Basic %s" % encodedData}
|
||||||
parameters={"limit": 50, 'offset': offset}
|
parameters={"limit": limit}
|
||||||
async with aiohttp.ClientSession(headers=headers) as bf_session:
|
while repeat == True:
|
||||||
async with bf_session.get(self.url, params=parameters) as r:
|
try:
|
||||||
bf_recipe_list = await r.json()
|
async with aiohttp.ClientSession(headers=headers) as bf_session:
|
||||||
await bf_session.close()
|
async with bf_session.get(self.url, params=parameters) as r:
|
||||||
|
bf_recipe_list = await r.json()
|
||||||
|
await bf_session.close()
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(e)
|
||||||
|
|
||||||
if bf_recipe_list:
|
if bf_recipe_list:
|
||||||
for row in bf_recipe_list:
|
loop +=1
|
||||||
recipe_id = row['_id']
|
for row in bf_recipe_list:
|
||||||
name = row['name']
|
recipe_id = row['_id']
|
||||||
element = {'value': recipe_id, 'label': name}
|
name = row['name']
|
||||||
result.append(element)
|
element = {'value': recipe_id, 'label': name}
|
||||||
return result
|
result.append(element)
|
||||||
else:
|
else:
|
||||||
return []
|
repeat = False
|
||||||
|
|
||||||
else:
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
if len(bf_recipe_list) != limit:
|
||||||
|
logging.info(loop)
|
||||||
|
repeat = False
|
||||||
|
else:
|
||||||
|
parameters={"limit": limit, 'start_after': recipe_id}
|
||||||
|
|
||||||
|
logging.info(len(result))
|
||||||
|
try:
|
||||||
|
newlist = sorted(result, key=lambda d: d['label'])
|
||||||
|
logging.error(newlist)
|
||||||
|
return newlist
|
||||||
|
except:
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_creation_path(self):
|
def get_creation_path(self):
|
||||||
creation_path = self.cbpi.config.get("RECIPE_CREATION_PATH", "upload")
|
creation_path = self.cbpi.config.get("RECIPE_CREATION_PATH", "upload")
|
||||||
|
@ -738,7 +755,7 @@ class UploadController:
|
||||||
|
|
||||||
brewfather = True
|
brewfather = True
|
||||||
result=[]
|
result=[]
|
||||||
self.bf_url="https://api.brewfather.app/v1/recipes/" + Recipe_ID
|
self.bf_url="https://api.brewfather.app/v2/recipes/" + Recipe_ID
|
||||||
brewfather_user_id = self.cbpi.config.get("brewfather_user_id", None)
|
brewfather_user_id = self.cbpi.config.get("brewfather_user_id", None)
|
||||||
if brewfather_user_id == "" or brewfather_user_id is None:
|
if brewfather_user_id == "" or brewfather_user_id is None:
|
||||||
brewfather = False
|
brewfather = False
|
||||||
|
|
Loading…
Reference in a new issue