rossant / ipymd

Use the IPython notebook as an interactive Markdown editor
BSD 3-Clause "New" or "Revised" License
484 stars 42 forks source link

Running ipymd in a script. #84

Closed stanleyng8 closed 7 years ago

stanleyng8 commented 7 years ago

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.

rossant commented 7 years ago

You can have a look at this function: https://github.com/rossant/ipymd/blob/master/ipymd/core/scripts.py#L114

stanleyng8 commented 7 years ago

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.