ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 19 Jun 2019 13:31:49 -0500best way to convert many notebooks from sagenb to jupyter?http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/I moved from sagenb to jupyter a while ago, but I still have a large number of sagenb notebooks that I have been converting one-by-one on demand. Is there a way to convert all of them at once and save them to a dedicated folder? Currently, when I start sage -notebook, I get to an interface where I can see all my sagenb notebooks and I have the option to click on any of them, convert and open in jupyter. I would actually like to convert all of them without opening them.
This is related to https://ask.sagemath.org/question/35873/how-to-automatically-convert-many-sws-to-ipynb/, but I suppose that there is a better way now. Thanks already for your help!Wed, 21 Mar 2018 08:36:13 -0500http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/Answer by eric_g for <p>I moved from sagenb to jupyter a while ago, but I still have a large number of sagenb notebooks that I have been converting one-by-one on demand. Is there a way to convert all of them at once and save them to a dedicated folder? Currently, when I start sage -notebook, I get to an interface where I can see all my sagenb notebooks and I have the option to click on any of them, convert and open in jupyter. I would actually like to convert all of them without opening them.
This is related to <a href="https://ask.sagemath.org/question/35873/how-to-automatically-convert-many-sws-to-ipynb/">https://ask.sagemath.org/question/358...</a>, but I suppose that there is a better way now. Thanks already for your help!</p>
http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/?answer=41684#post-id-41684Just to elaborate on @slelievre's answer: you don't have to install the SageNB exporter: it is already incorporated in recent versions of Sage; you can run it via the command `sage -n export`. More precisely, to list all your sagenb notebooks, run
sage -n export --list
Then to transform the notebook listed as `admin:12` (say), run
sage -n export --ipynb=output.ipynb admin:12
Instead of `admin:12`, you can also use directly the notebook name (without any extension, i.e. as it appears in the output of `sage -n export --list`):
sage -n export --ipynb=notebook_name.ipynb notebook_name
I guess you can easily put this into a loop to treat all your sagenb notebooks at once.Wed, 21 Mar 2018 09:22:19 -0500http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/?answer=41684#post-id-41684Comment by thethinker for <p>Just to elaborate on <a href="/users/1092/slelievre/">@slelievre</a>'s answer: you don't have to install the SageNB exporter: it is already incorporated in recent versions of Sage; you can run it via the command <code>sage -n export</code>. More precisely, to list all your sagenb notebooks, run </p>
<pre><code>sage -n export --list
</code></pre>
<p>Then to transform the notebook listed as <code>admin:12</code> (say), run </p>
<pre><code>sage -n export --ipynb=output.ipynb admin:12
</code></pre>
<p>Instead of <code>admin:12</code>, you can also use directly the notebook name (without any extension, i.e. as it appears in the output of <code>sage -n export --list</code>):</p>
<pre><code>sage -n export --ipynb=notebook_name.ipynb notebook_name
</code></pre>
<p>I guess you can easily put this into a loop to treat all your sagenb notebooks at once.</p>
http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/?comment=46947#post-id-46947I'm not sure I believe this answer. I'm running 8.7, and when I try that command I get
$ ./sage -n export -list
usage: sagenb-export [-h] [--log LOG] [--dot-sage DOT_SAGE] [--list]
[--ipynb IPYNB] [--print]
[sagenb]
sagenb-export: error: unrecognized arguments: -list
So I can't quite figure out what the correct commands are.Wed, 19 Jun 2019 13:31:49 -0500http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/?comment=46947#post-id-46947Comment by stan for <p>Just to elaborate on <a href="/users/1092/slelievre/">@slelievre</a>'s answer: you don't have to install the SageNB exporter: it is already incorporated in recent versions of Sage; you can run it via the command <code>sage -n export</code>. More precisely, to list all your sagenb notebooks, run </p>
<pre><code>sage -n export --list
</code></pre>
<p>Then to transform the notebook listed as <code>admin:12</code> (say), run </p>
<pre><code>sage -n export --ipynb=output.ipynb admin:12
</code></pre>
<p>Instead of <code>admin:12</code>, you can also use directly the notebook name (without any extension, i.e. as it appears in the output of <code>sage -n export --list</code>):</p>
<pre><code>sage -n export --ipynb=notebook_name.ipynb notebook_name
</code></pre>
<p>I guess you can easily put this into a loop to treat all your sagenb notebooks at once.</p>
http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/?comment=41830#post-id-41830Thanks, but `sage -n export --list` returns a table that looks pretty ugly in a text file:
```
'Unique ID | Notebook Name\n-------------------------------------------------------------------------------\n_sage_:0 | doc_browser_0\n_sage_:1 | doc_browser_0\n_sage_:2 | doc_browser_0\n_sage_:3 | doc_browser_0\n_sage_:4
```
and so on. Any idea how to get a list of tuples such as `[('admin:11', 'output11'), ('admin:12', 'output12')]`?Fri, 30 Mar 2018 03:32:13 -0500http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/?comment=41830#post-id-41830Comment by slelievre for <p>Just to elaborate on <a href="/users/1092/slelievre/">@slelievre</a>'s answer: you don't have to install the SageNB exporter: it is already incorporated in recent versions of Sage; you can run it via the command <code>sage -n export</code>. More precisely, to list all your sagenb notebooks, run </p>
<pre><code>sage -n export --list
</code></pre>
<p>Then to transform the notebook listed as <code>admin:12</code> (say), run </p>
<pre><code>sage -n export --ipynb=output.ipynb admin:12
</code></pre>
<p>Instead of <code>admin:12</code>, you can also use directly the notebook name (without any extension, i.e. as it appears in the output of <code>sage -n export --list</code>):</p>
<pre><code>sage -n export --ipynb=notebook_name.ipynb notebook_name
</code></pre>
<p>I guess you can easily put this into a loop to treat all your sagenb notebooks at once.</p>
http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/?comment=41787#post-id-41787Does this deal only with worksheets that live in the user's SageNB Notebook,
hidden in `~/.sage/sage_notebook.sagenb/home/...`?
What about converting a collection of .sws files in a different folder?Tue, 27 Mar 2018 04:13:27 -0500http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/?comment=41787#post-id-41787Answer by stan for <p>I moved from sagenb to jupyter a while ago, but I still have a large number of sagenb notebooks that I have been converting one-by-one on demand. Is there a way to convert all of them at once and save them to a dedicated folder? Currently, when I start sage -notebook, I get to an interface where I can see all my sagenb notebooks and I have the option to click on any of them, convert and open in jupyter. I would actually like to convert all of them without opening them.
This is related to <a href="https://ask.sagemath.org/question/35873/how-to-automatically-convert-many-sws-to-ipynb/">https://ask.sagemath.org/question/358...</a>, but I suppose that there is a better way now. Thanks already for your help!</p>
http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/?answer=41831#post-id-41831Certainly not the best way, but here is how I did it using the answer of @eric_g:
In a terminal, show a list of all notebooks:
sage -n export --list
Copy the output into the clipboard and paste into a text editor that allows block selection, e.g. geany in linux. Then create a new directory (e.g. 'fromsagenb') to make sure that you don't overwrite existing files and copy the block just containing the names into a new file in the empty folder, e.g. 'list.txt'.
Now execute the following code to convert all sage notebooks in that list into jupyter notebooks:
import os
os.chdir('/path_to_fromsagenb/')
f = open('list.txt')
str1 = f.read()
str2 = str1.splitlines()
for name in str2:
command = '~/Programs/SageMath/sage -n export --ipynb={0}.ipynb {0}'.format(name)
os.system(command)Fri, 30 Mar 2018 04:12:22 -0500http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/?answer=41831#post-id-41831Answer by slelievre for <p>I moved from sagenb to jupyter a while ago, but I still have a large number of sagenb notebooks that I have been converting one-by-one on demand. Is there a way to convert all of them at once and save them to a dedicated folder? Currently, when I start sage -notebook, I get to an interface where I can see all my sagenb notebooks and I have the option to click on any of them, convert and open in jupyter. I would actually like to convert all of them without opening them.
This is related to <a href="https://ask.sagemath.org/question/35873/how-to-automatically-convert-many-sws-to-ipynb/">https://ask.sagemath.org/question/358...</a>, but I suppose that there is a better way now. Thanks already for your help!</p>
http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/?answer=41682#post-id-41682There is the SageNB exporter:
- [https://github.com/vbraun/ExportSageNB](https://github.com/vbraun/ExportSageNB)Wed, 21 Mar 2018 09:08:43 -0500http://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/?answer=41682#post-id-41682