Skip to content

Conversation

@am-becker
Copy link

New features:

  • Supports Pages as well as Modules/Files
  • Supports caching so pages linked to from multiple pages are not re-requested
  • Performs HEAD request before actual file GET request to compare file size (much faster)
  • Fixes a bunch of bugs with canvas API returning weird results for locked/hidden files
  • Supports pagination (kinda) by increasing max page count

@benjavicente
Copy link
Owner

Hi @aaroexxt! Thanks for the PR! I will review soon.

I don't plan to maintain this library in the long-term, so I will see if a student org takes the repo. If you are interested on helping to maintaining it, I would be happy to known :)

Copy link
Owner

@benjavicente benjavicente left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only required changes would be to revert where there was the Google Drive download functionality and to fix my name :)

There is a lot of improvements that I will comment on issues, but all come form the fact that I wasn't really experienced on making good code back then 😅

Comment on lines 118 to +124
def __get(self, query: str, **kwarg):
"""Performs a GET request to the Canvas API with 250 items per page."""
# Extract existing parameters if provided
params = kwarg.pop("params", {})

# Ensure 'per_page' is set to 500
params["per_page"] = 500
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thing that's better for the per_page param to be defined per query, some endpoints might restrict the page size if I remember correctly.

Also, if you want to add a default to the params, it might be better to do something like this:

def __get(self, query: str, *, params = {"per_pagee": 500}, **kwarg):

Right now that implementation seems to override what was passed to __get

Comment on lines +178 to +183
pages_api_url = f"https://{self.domain}/api/v1/courses/{course_id}/pages"
response = requests.get(
pages_api_url,
headers={"Authorization": f"Bearer {self.token}"},
params={"per_page": 250} # Ensuring 250 pages per request
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ideally should use the __get method.

Comment on lines +326 to +327
if self._is_canvas_url(item["external_url"]):
self._download_canvas_page(course_id, item["external_url"], course_name)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here there was a method to download files from Google Drive, since at UC Chile it was common for courses to link to files there. I would keep the get_external_download_url check, or at least add a comment to say that here is where one could add a custom downloader for external services.

Complete file downloader for Canvas (Instructure)!

Features:
Originally by [Ben Javicente](https://github.com/benjavicente/canvas-file-downloader), essentially rewritten from scratch by [Aaron Becker](https://github.com/aaroexxt).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Originally by [Ben Javicente](https://github.com/benjavicente/canvas-file-downloader), essentially rewritten from scratch by [Aaron Becker](https://github.com/aaroexxt).
Originally by [Benjamin Vicente](https://github.com/benjavicente/canvas-file-downloader), essentially rewritten from scratch by [Aaron Becker](https://github.com/aaroexxt).

Benja is the spanish equivalent of Ben in english ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants