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).
答案 0 :(得分:2)
您必须使用Authorization标头和Content-Type应用程序/ json,然后笔记本将位于&#34;内容&#34;返回的字典的一部分。您可以使用jq获取字典的内容部分。如果在Mac OS X上只有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"
此外,您可以在jq部分&gt;之后添加输出重定向。 my_downloaded.ipynb
然后用jupyter笔记本打开它
对于/ user确保您的个人服务器已启动,为此您必须登录到您的用户帐户或进入您的控制面板,如果它未打开或已被剔除。 对于/ services,服务器通常被代理,因此它应始终打开。
用于/ services的网址
https://{YOUR_JUPYTER_DOMAIN}/services/{SERVICENAME}/api/contents/{PATH_TO_IPYNB}
答案 1 :(得分:1)
我不是jupyter的专家,但是如果您可以download as .ipynb
使用浏览器获取文件,那么只需重复该步骤并打开Chrome开发者工具,然后查找浏览器所访问的网址网络标签。您可以在开发人员工具中复制为curl命令,并将其粘贴到终端中以获得相同的效果。 (对不起,我没有正在运行的笔记本,以确保我的建议有效,希望它有所帮助)
答案 2 :(得分:1)
我也找到了简单的解决方案。但仅当笔记本不受令牌保护时才适用。笔记本可以通过wget
下载。
假设我们的笔记本位于以下网址:
http://<DOMAIN>:<PORT>/notebooks/my_notebook.ipynb
我们可以简单地将“notebooks”替换为“files”,并通过以下命令下载源ipynb文件:
wget http://<DOMAIN>:<PORT>/files/my_notebook.ipynb