Spaces:
Runtime error
Runtime error
arihantvyavhare
commited on
Commit
•
77b5632
1
Parent(s):
1b4a8a1
added command line functionality to .ipynb to .py converter
Browse files- converter.py +2 -3
- converter_update.py +28 -0
- tips.py +1 -0
converter.py
CHANGED
@@ -8,10 +8,9 @@ py_file = open(f"{filename}.py", "w+")
|
|
8 |
|
9 |
for cell in code['cells']:
|
10 |
if cell['cell_type'] == 'code':
|
11 |
-
if "#| export" in cell['source'][0]:
|
12 |
for line in cell['source'][1:]:
|
13 |
py_file.write(line)
|
14 |
-
|
15 |
py_file.write("\n")
|
16 |
elif cell['cell_type'] == 'markdown':
|
17 |
py_file.write("\n")
|
@@ -22,4 +21,4 @@ for cell in code['cells']:
|
|
22 |
py_file.write("#* " + line)
|
23 |
py_file.write("\n")
|
24 |
|
25 |
-
py_file.close()
|
|
|
8 |
|
9 |
for cell in code['cells']:
|
10 |
if cell['cell_type'] == 'code':
|
11 |
+
if cell['source'] and "#| export" in cell['source'][0]:
|
12 |
for line in cell['source'][1:]:
|
13 |
py_file.write(line)
|
|
|
14 |
py_file.write("\n")
|
15 |
elif cell['cell_type'] == 'markdown':
|
16 |
py_file.write("\n")
|
|
|
21 |
py_file.write("#* " + line)
|
22 |
py_file.write("\n")
|
23 |
|
24 |
+
py_file.close()
|
converter_update.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import argparse
|
3 |
+
|
4 |
+
parser = argparse.ArgumentParser(description='Convert .ipynb file to .py file')
|
5 |
+
parser.add_argument('input_file', help='Path to the input .ipynb file')
|
6 |
+
args = parser.parse_args()
|
7 |
+
file = args.input_file
|
8 |
+
|
9 |
+
code = json.load(open(file))
|
10 |
+
filename = file.split(".")[0]
|
11 |
+
py_file = open(f"{filename}.py", "w+")
|
12 |
+
|
13 |
+
for cell in code['cells']:
|
14 |
+
if cell['cell_type'] == 'code':
|
15 |
+
if cell['source'] and "#| export" in cell['source'][0]:
|
16 |
+
for line in cell['source'][1:]:
|
17 |
+
py_file.write(line)
|
18 |
+
py_file.write("\n")
|
19 |
+
elif cell['cell_type'] == 'markdown':
|
20 |
+
py_file.write("\n")
|
21 |
+
for line in cell['source']:
|
22 |
+
if line and line[0] == "#":
|
23 |
+
py_file.write(line)
|
24 |
+
else:
|
25 |
+
py_file.write("#* " + line)
|
26 |
+
py_file.write("\n")
|
27 |
+
|
28 |
+
py_file.close()
|
tips.py
CHANGED
@@ -21,3 +21,4 @@ shutil.rmtree(f"data/{query}")
|
|
21 |
|
22 |
|
23 |
|
|
|
|
21 |
|
22 |
|
23 |
|
24 |
+
|