Skip to content

Instantly share code, notes, and snippets.

@izikeros
Forked from jnothman/DataBricksNotebook2Ipynb.jq
Last active March 15, 2024 20:02
Show Gist options
  • Save izikeros/2259c87ab270f56c83cf79c62db69054 to your computer and use it in GitHub Desktop.
Save izikeros/2259c87ab270f56c83cf79c62db69054 to your computer and use it in GitHub Desktop.
[Databricks notebook to ipynb] Approximately convert DataBricks notebook (unzipped .dbc file) to ipynb using jq #jupyter #databricks #notebook #jq
.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