Skip to main content

Pip installable canvas API used by GT classes

Project description

Installation

Test Repo

This will be updated with the "formal" pypi repo eventually, but for now it's located here.

python3 -m pip install --upgrade --index-url https://test.pypi.org/simple/ canvas-lms-api

Formal Repo

This will be updated with the "formal" pypi repo eventually, but for now it's located here.

python3 -m pip install --upgrade canvas-lms-api

Alternatively, you can download the source code and pip install from that:

git clone https://github.gatech.edu/omscs-ta/canvas-lms-api
cd canvas-lms-api
pip install .

I would also strongly encourage you to use a .ta folder and house a .yml file in your home directory so you can just point to it with any/all scripts.

Usage:

Get Canvas Token

Found here: Canvas > Account > Settings > Approved Integrations: > New Access Token.

Get Course Number

There are really 2 ways.

  1. Use this tool to find all the courses and then use the number below (course is optional so you can set it later)
from canvas_lms_api import Canvas
grader = Canvas(base="https://gatech.instructure.com", token=YOUR TOKEN)
grader.GetCourses()
  1. Login to canvas

Get Assignments Example

from canvas_lms_api import Canvas
grader = Canvas(base="https://gatech.instructure.com", token=YOUR TOKEN, course=Your Course Number)
grader.GetAssignments()

Get Course Users Example

from canvas_lms_api import Canvas
grader = Canvas(base="https://gatech.instructure.com", token=YOUR TOKEN, course=Your Course Number)
grader.GetCourseUsers()

Submit Grades Example

from canvas_lms_api import Canvas
grader = Canvas(base="https://gatech.instructure.com", token=YOUR TOKEN, course=Your Course Number)
# Find your assignment id number see Get Assignments Example
assignment_id = ""
# Find your student id number see Get Course Users Example
student_id = ""

# Set score and comment
score = "75"
comment = "The student failed to complete the assignment\nAnd they got thse points wrong\n(-10) for poor guessing"
grader.SubmitGrade(assignment_id, student_id, score, comment, visibility=False)

Get StudentID by sortable name

from canvas_lms_api import Canvas
grader = Canvas(base="https://gatech.instructure.com", token=YOUR TOKEN, course=Your Course Number)
# If you have downloaded all submissions from canvas, the students files should be named with their sortable name in the string
# For your use case you'll need to parse them, but then when you have them you can get the student id from there. This will allow you to use the submit grades function.
sortable_name = "deanjimmy"
grader.GetIDBySortableName(sortable_name)

GetCourseModules

If you include "True" in GetCourseModules, this should allow you to get all full urls to modules.

I use the following to post links to lectures in my weekly announcements. (Though I have a shared repo for this if you ask for the url).

def lectures_to_dict(modules):
    res = {}
    for i in modules:
       # The lectures in my course use the form P#L# but you can tweak this to match how you name your sections, or even make a dictionary of your titles.
       m = re.search('(P\dL\d).*', i["name"]) 
       if m:
          for j in i["items"]:
              if j["position"] == 1:
                  print (j)
                  res[m.group(1)] = j["html_url"]
    return res
def replace_content(schedule, post_content, week_number, post_numbers, classID, lectures):
    # This is where we replace "variable content" in our weekly announcements.
    post_content = post_content.replace("|||HW1RELEASEDATE|||", schedule["hw1_assigned"] + ' T11:59:59Z')
    post_content = post_content.replace("|||HW2RELEASEDATE|||", schedule["hw2_assigned"] + ' T11:59:59Z')
....
    new_content = ""
    for j in post_content.split('\n'):
        found = False
        for i in lectures:
            if i in j:
                new_content += "* <a href=" + lectures[i] + ">" + i + "</a>" # Here is where we plop in the lectures. I just search for the dictionary strings in the weekly post content I have.
                found = True
        if not found:
            new_content += j + "\n"
    post_content = str(new_content) 
    return post_content
# get_week_announcement(week_number)  # This just returns the content of the weeks announcement.

# this is the high level series of functions I'll call to get a post put together, I also post to piazza in later functions not noted here.
grader = Canvas(base=_config["base"], token=_config["canvas_api"], course=_config["canvas_course"])


# This is the important function!
students_canvas = grader.GetCourseModules(True) # True will get all modules

res = lectures_to_dict (students_canvas)
post_content = get_week_announcement(week_number)
post_content = replace_content(_schedule, post_content, week_number, post_numbers, _config["piazzaclass"], res)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

canvas-lms-api-0.4.2.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

canvas_lms_api-0.4.2-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file canvas-lms-api-0.4.2.tar.gz.

File metadata

  • Download URL: canvas-lms-api-0.4.2.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.8.10

File hashes

Hashes for canvas-lms-api-0.4.2.tar.gz
Algorithm Hash digest
SHA256 c03e23ca07bc96ad1b438773f53a22afa05e4358f7798626ea5f696ee96996cf
MD5 24652c48e93600fd6e5ca142ef09bc8e
BLAKE2b-256 92b2e94c1efdba48cc49fd93cb8b3dd0c896de7e704e2180b17df961c0e5a31a

See more details on using hashes here.

File details

Details for the file canvas_lms_api-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for canvas_lms_api-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 15c547cbe9344a7b326756216c4ac368e3351185d36fbdadc4033ec9f302ce5c
MD5 36880346b10ef063fa74606e76bb60bc
BLAKE2b-256 182e68e00ac67479867d5f37ea9b182bce0e2a85e8a6f3033f9636b0400d7e60

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page