From 4ce2169785d6da550ae6c8f9afd3395bb37ef399 Mon Sep 17 00:00:00 2001 From: Tyler Clair Date: Fri, 8 May 2026 12:05:31 -0600 Subject: [PATCH] feat: add base URL option for fetching specs in canvas_api_builder --- README.md | 9 +++++---- canopy/scripts/canvas_api_builder.py | 13 +++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9a39c4d..36dafe4 100644 --- a/README.md +++ b/README.md @@ -98,13 +98,13 @@ You can use the `canopy_build` script to download the spec files, generate the C **Downloading or updating all spec files** ```bash -canopy_build fetch-specs --specs-dir specs/ +canopy_build fetch-specs --specs-dir specs/ --base-url https://yourschool.instructure.com ``` **Download or update an individual spec file** ```bash -canopy_build fetch-specs --specs-dir specs/ --spec accounts.json +canopy_build fetch-specs --specs-dir specs/ --base-url https://yourschool.instructure.com --spec accounts.json ``` > **Note:** Instructure has started to timeout the download script after so many downloads, after that you will get 202 errors. It's recommended to either download them individually or use a downloading extension in your browser to download all the spec files. @@ -178,6 +178,7 @@ Pass it to any command that processes multiple specs via `--exclude-file`: ```bash canopy_build fetch-specs \ --specs-dir specs/ \ + --base-url https://yourschool.instructure.com \ --exclude-file excluded_specs.toml canopy_build build-all \ @@ -238,7 +239,7 @@ canopy_docs generate-all \ ```python from canvas_client import CanvasClient -canvas_url = "https://abc.instructure.com" +canvas_url = "https://yourschool.instructure.com" token = "your_token_here" client = CanvasClient(canvas_url, token, max_per_page=100) @@ -281,7 +282,7 @@ import asyncio from canvas_client import CanvasClient from time import perf_counter -canvas_url = "https://abc.instructure.com" +canvas_url = "https://yourschool.instructure.com" token = "your_token_here" client = CanvasClient(canvas_url, token, max_per_page=100) diff --git a/canopy/scripts/canvas_api_builder.py b/canopy/scripts/canvas_api_builder.py index cea42c6..d0465fe 100644 --- a/canopy/scripts/canvas_api_builder.py +++ b/canopy/scripts/canvas_api_builder.py @@ -300,9 +300,18 @@ def rebuild( type=click.Path(exists=True, dir_okay=False, readable=True, path_type=Path), help="TOML file listing spec filenames to exclude from downloading.", ) -def fetch_specs(specs_dir: Path, spec: str | None, exclude_file: Path | None) -> None: +@click.option( + "-b", + "--base-url", + default="https://canvas.instructure.com", + show_default=True, + help="Your Canvas instance URL (e.g. https://yourschool.instructure.com). The /doc/api/ path is appended automatically.", +) +def fetch_specs( + specs_dir: Path, spec: str | None, exclude_file: Path | None, base_url: str +) -> None: """Fetch spec files from the Instructure Canvas API docs.""" - base_url = "https://canvas.instructure.com/doc/api/" + base_url = base_url.rstrip("/") + "/doc/api/" excluded = load_excluded_specs(exclude_file) if spec: