Skip to content
Snippets Groups Projects
Commit d8112a62 authored by Konrad Firley's avatar Konrad Firley
Browse files

added conversion script that converts all ipynb file to json and it work...

added conversion script that converts all ipynb file to json and it work cascading -> converts every thing in a folder even in sub and subsub... folders
parent 859249d7
No related branches found
No related tags found
No related merge requests found
import json
import os
from os import listdir
#jupyter nbconvert --to html */*/*.ipynb <- command converts every ipynb to html
############################################################################################################
# Info: this scipt is used to create converted copys of ipynb notebooks.
# The Copy is a converted json files. And they shoul be put automagically in the same folder.
# It works as intended, only the console output might be a little confusing because
# it is still a work in Progress.
#
# Running: put in all missing bits, like your file path and then it is able to run
# Filepath: should be the top folder where all files are at -> machine-learning-services-main
#
# Any Questions? ask Konrad :)
#############################################################################################################
#like this: /./Users/Lomikukus/Coding/ML_Projekt/machine-learning-services-main/
directory = os.fsencode('/./Users/Lomikukus/Coding/ML_Projekt/machine-learning-services-main/')
f = []
#walks over all files and folders that are listed in the folder which u used in path
for (root, dirnames, filenames) in os.walk(directory): #this outputs a list of all roots, directorie names, and filenames
for file in filenames: #for each file found...
#sprint(file)
pathtofile = os.path.join(root, file)
#print(pathtofile)
filename = os.fsdecode(file)
filenameX = str(filename)
#print(filenameX)
if filename.endswith(".ipynb"): #...it checks if the file ends in .ipynb...
print(os.path.join(root, file))
print("found")
with open(pathtofile, mode="r", encoding="utf-8") as sf: #...if true then they are being corectly converted to a good json format
mynotebook = json.loads(sf.read())
namejson = "notebook.json"
namejson = os.fsencode(namejson)
newfilepath = os.path.join(root, namejson)
with open(newfilepath, mode="w", encoding="utf-8") as newjson:
json.dump(mynotebook, newjson, ensure_ascii=False, indent=4)
print("converted")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment