-
-
Save nobucshirai/91b63d447c49d8d517772d6c8bb48663 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env python | |
| import sys | |
| import json | |
| from optparse import OptionParser | |
| # loadJson :: String -> Dict | |
| def loadJson(filePath): | |
| with open(filePath, 'r') as f: | |
| jsonDict = json.load(f) | |
| return jsonDict | |
| # existsTag :: String -> String -> Bool | |
| def existsTag(tag, inputs): | |
| if tag in str(inputs): | |
| return True | |
| else: | |
| return False | |
| # existsKey :: String -> String -> Bool | |
| def existsKey(key, inputs): | |
| if key in inputs: | |
| return True | |
| else: | |
| return False | |
| # showJson :: IO () | |
| def showJson(jsonDict): | |
| print(json.dumps(jsonDict, ensure_ascii=False, indent=1)) | |
| if __name__ == '__main__': | |
| usage="Usage: ipm.py input_file.ipynb > output_file.ipynb" | |
| parser = OptionParser(usage=usage) | |
| (options, args) = parser.parse_args() | |
| args = sys.argv | |
| if len(args) != 2: | |
| parser.error("The number of args is not correct.") | |
| exit(1) | |
| jsonDict = loadJson(args[1]) | |
| for i in range(len(jsonDict['cells'])): | |
| if existsTag("#erase", jsonDict['cells'][i]['source']): | |
| jsonDict['cells'][i]['source'] = '' | |
| if existsKey('outputs', jsonDict['cells'][i]): | |
| jsonDict['cells'][i]['outputs'] = [] | |
| if existsKey('execution_count', jsonDict['cells'][i]): | |
| jsonDict['cells'][i]['execution_count'] = None | |
| showJson(jsonDict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment