This course is incredible, but I wanted to see the code in my own IDE. I tried following advice from this post, but it did not work due to a limitation apparently in Google Chrome: Downloading your Notebook, Downloading your Workspace and Refreshing your Workspace
This script works for me. Obviously run this at your own risk:
# Build a backup tarball of this folder and show a download link that works
# inside the embedded course notebook (opens the file in a new top-level tab,
# because Chrome blocks downloads that start inside the course page's frame).
import os, shutil, subprocess
from IPython.display import HTML, display
def backup_and_download(filename="project_backup.tar.gz"):
tmp_path = os.path.join("/tmp", filename)
# Write to /tmp first and exclude the old tarball, so tar never archives itself
result = subprocess.run(
["tar", f"--exclude=./{filename}", "-czf", tmp_path, "."],
capture_output=True, text=True,
)
if result.returncode > 1:
print("tar failed:\n" + result.stderr)
return
if result.stderr:
print("tar warnings:\n" + result.stderr)
shutil.move(tmp_path, filename)
size_kb = os.path.getsize(filename) / 1024
# Assumes this notebook sits in the Jupyter root folder (true for this lab)
display(HTML(f"""
<a href="#" style="font-weight:bold; font-size:1.1em"
onclick="var base = location.pathname.split('/lab')[0];
window.open(location.origin + base + '/files/{filename}?download=1', '_blank');
return false;">
Download {filename} ({size_kb:.0f} KB)
</a>
<div style="color:gray; font-size:0.9em">Opens a new tab that starts the download. If nothing happens, allow pop-ups for this site.</div>
"""))
backup_and_download()