Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
machine-learning-services
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KI_LAB
machine-learning-services
Commits
b4e922e9
Commit
b4e922e9
authored
1 year ago
by
Konrad Firley
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
convert.py
+28
-21
28 additions, 21 deletions
convert.py
with
28 additions
and
21 deletions
convert.py
+
28
−
21
View file @
b4e922e9
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment