-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to mealie-API of v1.0.0-beta5 #20
Conversation
…add food/unir-parsing for scaling-function
Wow, thanks a lot 😃. I need some time to look at the changes, but this looks very promising. |
Ok, spent the best part of the evening getting my mealie fork up to date. Maybe I can try your changes against my fork tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems there are a few things left to do, and I noticed that the tests also need to be modified. I'll try to work on this tomorrow evening maybe - good night 😊
kptncook/mealie.py
Outdated
RecipeStep(title=None, text=step.title.de, image=step.image) for step in kcin.steps | ||
], | ||
"recipeIngredient": [ | ||
RecipeIngredient(food=mealie_client.get_food_by_name(ig.ingredient.localized_title.de.split(",")[0]), quantity=(ig.quantity/2.0) if ig.quantity is not None else None, unit=mealie_client.get_unit_by_name(ig.measure if hasattr(ig, "measure") else None), note=ig.ingredient.localized_title.de.split(",")[1] if len(ig.ingredient.localized_title.de.split(","))>1 else None) # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoa! 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for that 😬 The line has grown over the course of 3 weeks 😅 Feel free to simplify, my first goal was to get it working
kptncook/mealie.py
Outdated
|
||
return all_tags_parsed | ||
|
||
def get_all_foods(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, interesting - will test that tomorrow 😀
all_recipes.extend([Recipe.parse_obj(recipe) for recipe in r.json()["items"]]) | ||
|
||
page = 2 | ||
while page <= r.json()["total_pages"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I guess get("/recipes") didn't get all? 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope and iirc the api call is already paged per default to 50. Additionally, for larger mealie instances it take a considerable time to get an answer from mealie, so I left it with a pagesize of 50.
I've seen, that sometimes recipes get uploaded again in a later run of sync-with-mealie (with "-1" as slug suffix). Idon't know yet, when and why this happens as I hadn't time to investigate until now, so just as a hint. |
…recipe_id works again
…uff -> all tests are working again
…t for something different in the future)
…e content of a response is consumed (done by r.json()) stick to documented httpx api if there's not a good reason (evidence like a reproducible bug) to do things differently
…cessary to fetch ids from the api? seems unlikely)
Oh, one more thing: do you have a local test installation? If not you might want to take a look at my mealie fork. If you run it locally you get full access to the standard swagger api documentation at api docs. You can also use the jupyter notebooks in the notebooks dir to test adding recipes. Makes debugging a lot easier. Have a nice weekend, |
At the moment this is working for me but all recepies are English. Here is a quick workaround for getting German KptnCook recipies into Mealie.
Example: |
Hi @ulimanaio, hmm, weird - the receipts I imported into mealie are all german by default. Maybe it's a But good to know there's a way to set the language explicitly 😄. |
I've updated the mealie-client for API-version of v1.0.0-beta5. Since there is yet no documentation of the API changes, I just reverse engineered what the webfrontend does.
Additionally, I changed the way, the kptncook-client downloads the recipes (changed the Accept-Header), so the json contains the step-images in a more managable manner and so it now also uploads the assets for step-images in mealie.
As mealie v1 introduces a scaling-function for recipes, I added a food- and unit-parser so the quantity of the ingredients gets handled correctly and you can scale the amount of the ingredients to whatever portion count you want. Kptncook has a default portion size of 2, so I divide the amount by 2 to have a default portion count of 1 as mealie can currently only calculate multiple of the default portion count, but not in single steps.
I also fixed the tag-setting, as its basically the same as for food and units.
Sorry for not following your naming guideline (sometimes camelCase instead of snake case and use of Alias as of the API of mealie wants camelCase naming and I was in a rush). But you`re welcome to make any refactoring you want :)
And sorry for one big Commit and Pull request, I hope the changes are clear enough.