Running ipymd in a script.
stanleyng8 opened this issue · 2 comments
I want to do the following with a script. Scan the root and subdrectories for *.ipynb files. Then run the script to convert the *.ipynb for git check in. The reverse would be to scan the root and subdirectories for *.md and convert them to *.ipynb.
Scanning is relatively straightforward with
import os
search_dir ="."
for dirpath, subdirs, filenames in os.walk(search_dir):
for filename in filenames:
if filename.endswith(".ipynb"):
# Convert file to *.md
but how do I call ipymd to convert the file to *.md? Thanks very much.
You can have a look at this function: https://github.com/rossant/ipymd/blob/master/ipymd/core/scripts.py#L114
Thanks. I had just figured it out after stepping through the code. Initially I didn't install it but left it as a subdirectory. For some reason, the formats weren't recognized. Anyway, I got out the syntax I wanted.
ipymd.convert_files(search_dir, overwrite=True, from_='notebook', to='markdown', recursive=False, extension="ipynb")
It is a very nice package. I think I might still scan the directories instead of recursively going through it via ipymd. That way I can check the timestamps and be sure that only newer versions are overwriting the older ones.