Loading Jupyter notebook from external url using CLI
I need to download a .ipynb file to a terminal and run it (using nbconvert
or something like that).
-
I tried to use
wget
andcurl
for this, but I got a web page (with tags and Javascript code) instead of an executable laptop. -
Then I used Jupyter REST API . To get the contents of the notebook, I used
/api/contents/<path>/<file>
Ie I just changednotebooks
toapi/contents
in the url. I got the content of the notebook with some extra text (I'll have to filter it later) and ... as one line. So, I have a lot of work to do to convert this string to a working notebook.
Is it possible to download the Jupyter notebook through the terminal and get a working .ipynb file (just like the file can be downloaded using download as .ipynb
the Jupyter Web UI).
source to share
I'm not a jupyter expert, but if you can make download as .ipynb
and receive the file using a browser, then just repeat this step using the Chrome developer tools and find the URL that the browser hit the web tab. You can copy the curl command to developer tools and paste it into the terminal to get the same effect. (sorry i don't have a working laptop to make sure my advice works, hope it helps)
source to share
You have to use the authorization header and the Content-Type / json application and then the notebook will be in the "content" part of the returned dictionary. You can use jq to get some of the contents of the dictionary. If on Mac OS X justbrew install jq
curl -H "Authorization: Token {YOUR_TOKEN}" -H "Content-Type: application/json" -XGET https://{YOUR_JUPYTER_DOMAIN}/user/{USERNAME}/api/contents/{PATH_TO_IPYNB} | jq ".content"
Also you can add output redirection after jq> my_downloaded.ipynb part
And then just open it with jupyter notebook
For user / user, make sure your personal server is running, for this you need to log into your account or log into control panel if it is not enabled or has not been discarded. For / services, the server is usually proxied, so it should always be enabled.
URL to use / services
https://{YOUR_JUPYTER_DOMAIN}/services/{SERVICENAME}/api/contents/{PATH_TO_IPYNB}
source to share
I also found a simple solution. But this is only applicable if the laptop is not protected by a token . Laptops can be downloaded using wget
.
Let's assume our laptop is at the following url:
http://<DOMAIN>:<PORT>/notebooks/my_notebook.ipynb
We can simply replace "laptops" with "files" and load the original ipynb file with the following command:
wget http://<DOMAIN>:<PORT>/files/my_notebook.ipynb
source to share