Created
May 11, 2018 01:36
-
-
Save benhg/3cb45c8e3b1150fb2b3ed1f46f1542be to your computer and use it in GitHub Desktop.
Get total word count of all markdown cells in all .ipynb files in a given directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
import glob | |
from IPython.nbformat import current | |
word_count = 0 | |
directory = "dirpath" | |
for direc in glob.glob("{}*.ipynb".format(directory)): | |
with io.open(direc, 'r', encoding='utf-8') as f: | |
nb = current.read(f, 'json') | |
for cell in nb.worksheets[0].cells: | |
if cell.cell_type == "markdown": | |
word_count += len(cell['source'].replace('#', '').lstrip().split(' ')) | |
print(word_count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment