Skip to content

Instantly share code, notes, and snippets.

@jnothman
Last active September 12, 2022 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jnothman/a72777e2f59137623ed6d2a214feae06 to your computer and use it in GitHub Desktop.
Save jnothman/a72777e2f59137623ed6d2a214feae06 to your computer and use it in GitHub Desktop.
Approximately convert DataBricks notebook (unzipped .dbc file) to ipynb
.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