Download a file from a URL to a local path.
(url, dest_path)
| 42 | return url.startswith("http://") or url.startswith("https://") or url.startswith("//") |
| 43 | |
| 44 | def download_file(url, dest_path): |
| 45 | """Download a file from a URL to a local path.""" |
| 46 | if os.path.exists(dest_path): |
| 47 | #print(f"Skipping {url} (already downloaded to {dest_path})") |
| 48 | return |
| 49 | try: |
| 50 | if url.startswith("//"): |
| 51 | url = "https:" + url # Default to HTTPS for protocol-relative URLs |
| 52 | if url.startswith("https://oss.maxcdn.com/"): |
| 53 | url = url.replace("https://oss.maxcdn.com/", "https://cdnjs.cloudflare.com/ajax/") |
| 54 | response = requests.get(url, timeout=10) |
| 55 | response.raise_for_status() |
| 56 | with open(dest_path, "wb") as f: |
| 57 | f.write(response.content) |
| 58 | print(f"Downloaded {url} to {dest_path}") |
| 59 | except Exception as e: |
| 60 | print(f"Failed to download {url}: {e}") |
| 61 | |
| 62 | def add_version_to_filename(filename, version): |
| 63 | """Add version number to filename if not already present. |
no test coverage detected
searching dependent graphs…