Last active
September 12, 2022 06:35
-
-
Save jnothman/a72777e2f59137623ed6d2a214feae06 to your computer and use it in GitHub Desktop.
Approximately convert DataBricks notebook (unzipped .dbc file) to ipynb
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
.language as $lang | | |
{ | |
"metadata" : { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.9.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"cells": .commands | [ | |
.[] | | |
( | |
.command | | |
(capture("^%(?<cellLang>\\w+)\\s(?<remainder>.*)") // {cellLang: $lang, remainder: .}) | |
as { $cellLang, $remainder } | | |
{ | |
cell_type: (if $cellLang == "md" then "markdown" else "code" end), | |
source: [ | |
if $lang == $cellLang or $cellLang == "md" then "" else "%%" + $cellLang + "\n" end, | |
$remainder | if $cellLang == "md" then gsub("(?<head>(^|\n)#+)"; "\(.head) ") else . end | |
], | |
metadata: {} | |
} | | |
. + if .cell_type == "code" then {outputs: [], execution_count: 0} else {} end | |
) | |
] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment