Skip to content
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

Merged
merged 34 commits into from
Dec 3, 2022
Merged

Update to mealie-API of v1.0.0-beta5 #20

merged 34 commits into from
Dec 3, 2022

Conversation

alexdetsch
Copy link
Collaborator

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.

@ephes
Copy link
Owner

ephes commented Nov 28, 2022

Wow, thanks a lot 😃. I need some time to look at the changes, but this looks very promising.

@ephes
Copy link
Owner

ephes commented Nov 29, 2022

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.

Copy link
Owner

@ephes ephes left a 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 😊

README.md Show resolved Hide resolved
kptncook/__init__.py Outdated Show resolved Hide resolved
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa! 😅

Copy link
Collaborator Author

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/api.py Outdated Show resolved Hide resolved
kptncook/mealie.py Outdated Show resolved Hide resolved

return all_tags_parsed

def get_all_foods(self):
Copy link
Owner

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 😀

kptncook/mealie.py Outdated Show resolved Hide resolved
all_recipes.extend([Recipe.parse_obj(recipe) for recipe in r.json()["items"]])

page = 2
while page <= r.json()["total_pages"]:
Copy link
Owner

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? 😬

Copy link
Collaborator Author

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.

@alexdetsch
Copy link
Collaborator Author

alexdetsch commented Nov 30, 2022

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.

kptncook/mealie.py Outdated Show resolved Hide resolved
@ephes ephes merged commit b70a78c into ephes:main Dec 3, 2022
@ephes
Copy link
Owner

ephes commented Dec 3, 2022

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,
Jochen

@ulimanaio
Copy link

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.

  1. Share via email
  2. Open Link in email.
  3. Copy URL
  4. Delete everything after and including "_branch_match_id" ...
  5. Add "lang=de" behind "?"

Example:
https://mobile.kptncook.com/recipe/pinterest/Tomaten-Tortelloni-Suppe/513faa3b?lang=de

@ephes
Copy link
Owner

ephes commented Mar 23, 2023

Hi @ulimanaio,

hmm, weird - the receipts I imported into mealie are all german by default. Maybe it's a
setting in your kptncook account or something like this?

But good to know there's a way to set the language explicitly 😄.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants