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

fixed stuff with the convert.py and added new commands so it is easier to understand

parent a5c0b97c
No related branches found
No related tags found
No related merge requests found
......@@ -16,31 +16,38 @@ from os import listdir
#############################################################################################################
#like this: /./Users/Lomikukus/Coding/ML_Projekt/machine-learning-services-main/
# ./ should work 99% of the time
print("hello")
directory = os.fsencode('./') #th
directory = os.fsencode('/./Users/Lomikukus/Coding/ML_Projekt/machine-learning-services-main/')
print("yes")
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
try:
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")
for file in filenames: #for each file found...
#sprint(file)
pathtofile = os.path.join(root, file)
#print(pathtofile)
filename = os.fsdecode(file)
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")
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)
#this part opens a new file in write mode and creates a notebook.json
with open(newfilepath, mode="w", encoding="utf-8") as newjson:
json.dump(mynotebook, newjson, ensure_ascii=False, indent=4)
print("converted")
except:
print("error")
\ No newline at end of file
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