MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / exportAsPythonScript

Function exportAsPythonScript

frontend/src/utils/notebookExport.ts:264–291  ·  view source on GitHub ↗
(
  cells: PythonCell[],
  scriptName: string = 'DataKit_Script'
)

Source from the content-addressed store, hash-verified

262 * Export notebook cells as plain Python script
263 */
264export const exportAsPythonScript = (
265 cells: PythonCell[],
266 scriptName: string = 'DataKit_Script'
267): void => {
268 try {
269 const pythonContent = cells
270 .filter(cell => cell.type === 'code')
271 .map((cell, index) => {
272 const cellComment = `# Cell ${index + 1}\n`;
273 return cellComment + cell.code;
274 })
275 .join('\n\n');
276
277 const blob = new Blob([pythonContent], { type: 'text/plain' });
278 const url = URL.createObjectURL(blob);
279 const a = document.createElement('a');
280 a.href = url;
281 a.download = `${scriptName}.py`;
282 document.body.appendChild(a);
283 a.click();
284 document.body.removeChild(a);
285 URL.revokeObjectURL(url);
286
287 } catch (error) {
288 console.error('Failed to export Python script:', error);
289 throw new Error('Python script export failed. Please try again.');
290 }
291};
292
293/**
294 * Export notebook cells as Markdown document

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected