-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
addition -* tag name / C2DH/jdh-notebook#97
- Loading branch information
Showing
2 changed files
with
77 additions
and
35 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# parse the cells tag and add "-*" at the end of a tag beginning with "figure" | ||
import sys | ||
import nbformat | ||
|
||
|
||
def add_figure_tag(notebook): | ||
for cell in notebook.cells: | ||
tags = cell.get("metadata", {}).get("tags", []) | ||
if tags: | ||
for tag in tags: | ||
if tag.startswith("figure"): | ||
print("add -* to the tag: {}".format(tag)) | ||
tags.append(tag + "-*") | ||
tags.remove(tag) | ||
break | ||
return notebook | ||
|
||
|
||
|
||
# main function | ||
def main(): | ||
# get the notebook file name | ||
notebook_file = sys.argv[1] | ||
# read the notebook file | ||
with open(notebook_file) as f: | ||
nb = nbformat.read(f, as_version=4) | ||
# add the figure tag | ||
nb = add_figure_tag(nb) | ||
# write the notebook file | ||
with open(notebook_file, 'w') as f: | ||
nbformat.write(nb, f) | ||
|
||
|
||
#call the main function | ||
if __name__ == '__main__': | ||
main() | ||
|
||
#call the script from the terminal | ||
#!python technical_review.py paper.ipynb | ||
|
||
#call the script from the notebook | ||
#%run technical_review.py paper.ipynb |