-
Notifications
You must be signed in to change notification settings - Fork 96
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
Batch add recipes #288
Comments
My coding knowledge is nearly non-existent, most of my Github activity is reading and learning but.... Does this cookbook app have any type of CLI that supports the import recipe feature? If so wouldn't a very simple shell script be able to achieve this? It may not be the best solution, but for an app like this with a small community, it may be a workable intermediary solution until a more polished & permanent method is found. |
Unfortunately no, there is no cli. I checked the docs and found no way to add some commands to occ. This would also require shell access which is not given for quite some installations. |
@christianlupus You're right, this is not documented, but it's pretty straightforward. For an example, you can see the nextcloud/news repository.
|
@mcorteel Thanks for clarifying. I was not aware of that. Nice to know that. About the main issue: Another (yet completely independent from the app) approach would be to use curl in a local (bash) script to iterate over all to be imported URLs and push them to the |
I looked into this, but it looks like
It also returned a 500 status code. I am able to add this recipe via the web interface. |
@geeseven Apart from the fact that I was not able to fetch any recipe from the URL in the command, I was able to import via command line interface. First, I need a valid app token. Youi can create it manually or programmatically. The programmatic approach is described in the NC docs.
I open the required URL in a browser (or instruct the user of my script to do so). Meanwile, I can try to fetch some data from the endpoint provided (see docs). Once the user has logged in, I get
I need to save/store the app password somewhere. Now, I can use bearer authentication to import a single recipe.
As a result, I get the recipe as JSON+LD. Of course the app password I do not need to recreate each time but only once. |
I should have not included a foodnetwork.com recipe in my example. We learned in #115, that site is very different in different regions. Are you using Nextcloud's api instead of the cookbook app api? |
I released that I was using an 'app password' where I had removed 'Allow filesystem access'. Once I enabled that, it works! $ curl -s \
> --user user:password \
> --request POST https://example.com/index.php/apps/cookbook/import \
> --header "Content-Type: application/x-www-form-urlencoded" \
> --data "url=https://www.chefkoch.de/rezepte/1807401292413281/Zwiebelsuppe-nach-Art-der-legendaeren-Pariser-Marktfrauen.html" \
> |jq .name
"Zwiebelsuppe nach Art der legendären Pariser Marktfrauen" |
$ ./import-cookbook.sh temp
https://www.chefkoch.de/rezepte/1807401292413281/Zwiebelsuppe-nach-Art-der-legendaeren-Pariser-Marktfrauen.html added
https://www.chefkoch.de/rezepte/1807401292413281/Zwiebelsuppe-nach-Art-der-legendaeren-Pariser-Marktfrauen.html "Another recipe with that name already exists"
https://example.com "Could not find recipe element"
$ cat temp
https://www.chefkoch.de/rezepte/1807401292413281/Zwiebelsuppe-nach-Art-der-legendaeren-Pariser-Marktfrauen.html
https://www.chefkoch.de/rezepte/1807401292413281/Zwiebelsuppe-nach-Art-der-legendaeren-Pariser-Marktfrauen.html
https://example.com
$ cat import-cookbook.sh
#!/usr/bin/env bash
HOST="https://nextcloud.example.com"
USER="user"
PASSWORD="password"
# If using an 'app password' ensure 'Allow filesystem access' is enabled.
IFS=""
while read -r url
do
result=$(curl -s \
--user "$USER:$PASSWORD" \
--request POST "$HOST"/index.php/apps/cookbook/import \
--header "Content-Type: application/x-www-form-urlencoded" \
--data "url=$url")
if [[ ${result} = \{\"\@context\"* ]] ; then
echo "$url added"
else
echo "$url ${result}"
fi
done < "$1"
$ shellcheck import-cookbook.sh
$ @mrzapp, What do you think about adding this script into the repository? |
@geeseven my personal opinion is that scripts should be included in the standard fashion, runnable with |
I recently asked at the NC server team. They have a (valid) remark on that: Either we put it on a wiki page or directly in the |
@christianlupus good point. Let's put it in the documentation folder, I think that makes more sense than the wiki |
@mrzapp, I agree that this script should only be used as a stop gap till a proper solution is developed. Where should the documentation folder be located? |
@geeseven a |
I am perfectly fine with a |
I am starting to have mixed thoughts on a What about something like |
@christianlupus, I agree that proper documentation is needed, but I am just not sure this is the best starting point. If you got something in mind, feel free to get the ball rolling. I do not care about credit for this script. It was something I whipped up for you while working on a qutebrowser userscript. I can add a recipe with a single keystroke. 😁 |
Is your feature request related to a problem? Please describe.
From time to time I find some recipes I want to add to the app's storage. Typically this happens in batches as if I start to dig into some recipe databases, I do find quite some recipes I find interesting.
I now have to add all the recipes URL by URL waiting for the cloud to fetch and store the relevant data until I can enter the next URL.
Describe the solution you'd like
I would like to have an option to enter a list of URLs (textarea). This should then be parsed line by line and imported as best as it can do now.
To avoid issues with timeouts, I suggest to simply do this on the client side. So a small JS script reads the textarea line by line and calls AJAX requests just as in the current implementation for the single-URL import. From the server side no change is needed. It is merely a UX issue with a small script to automate it.
Describe alternatives you've considered
Except for manually adding the recipes, I have not had a good idea. Maybe, one could use a local file + a bash script calling a series of curl invocations to simulate the REST calls but that's all I could think of at the moment.
The text was updated successfully, but these errors were encountered: