Reputation: 3157
I need to download .ipynb-file in a terminal and than run it (using nbconvert
or something like that).
I tried use wget
and curl
for this, but I got web page (with tags and Javascript code) instead of runnable Notebook.
Then I used Jupyter REST API. To get a notebook's content I used /api/contents/<path>/<file>
I.e. I simply changed notebooks
to api/contents
in URL. I got a content of the notebook with some additional text (I'll have to filter it later), and... in a form of one line. So, I have a lot of work to convert this one line into a working notebook.
Is it possible to download Jupyter notebook via terminal and to get working .ipynb-file (the same as file can be downloaded by download as .ipynb
in Jupyter Web UI).
Upvotes: 6
Views: 11299
Reputation: 3157
I've also found simple solution. But it is applicable only if the notebook isn't secured by a token. The notebooks can be downloaded by wget
.
Assume that our notebook is located by the following URL:
http://<DOMAIN>:<PORT>/notebooks/my_notebook.ipynb
We can simply replace "notebooks" to "files" and download the source ipynb-file by the following command:
wget http://<DOMAIN>:<PORT>/files/my_notebook.ipynb
Upvotes: 2
Reputation: 1495
You have to use the Authorization header and Content-Type application/json and then the notebook will be in the "content" part of the dictionary that is returned. You can use jq to get the content part of the dictionary. If on Mac OS X just brew 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 the jq part > my_downloaded.ipynb
And then just open it with jupyter notebook
For /user make sure your personal server is started, for this you have to login to your user account or go into your Control panel, if it is not on or has been culled. For /services the server is usually being proxied so it should always be on.
The Url to use for /services
https://{YOUR_JUPYTER_DOMAIN}/services/{SERVICENAME}/api/contents/{PATH_TO_IPYNB}
Upvotes: 2
Reputation: 13404
I'm no expert on jupyter, but if you can do download as .ipynb
and get the file using the browser, then just repeat that step with Chrome developer tools open, and look for the URL that the browser hit in the network tab. You can copy as curl command in developer tools and paste that in a terminal to get the same effect. (sorry I don't have a running notebook to ensure that my advice works, hope it helps)
Upvotes: 1