import requests import nbformat from nbconvert import PythonExporter # URL del archivo .ipynb url = "https://sd1.d2.ipsilum.com/jupiter/Victoriano/areas_genericas_polyfill_countpoints_file.ipynb" # Descarga el archivo .ipynb response = requests.get(url) notebook_content = response.json() # Obtiene el contenido del notebook en formato JSON # Convierte el contenido .ipynb a un objeto nbformat notebook_node = nbformat.reads(response.text, as_version=4) # Utiliza el PythonExporter para convertir el notebook a un script Python python_exporter = PythonExporter() python_code, _ = python_exporter.from_notebook_node(notebook_node) texto_filtrado = "" os_imported = False for line in python_code.splitlines(): if line.find("pip install") != -1: if line.find("os.system(") == -1: if not os_imported: line = f'import os\nos.system("{line}")\n' os_imported = True else: line = f'os.system("{line}")\n' texto_filtrado = texto_filtrado + f"{line}\n" # Guarda el código Python en un archivo local with open("archivo_convertido_2.py", "w") as f: f.write(texto_filtrado) print("Archivo guardado como archivo_convertido.py")