GT类使用的Pip可安装画布API
canvas-lms-api的Python项目详细描述
安装
回购测试
最终,它将被更新为“正式的”pypi回购,但现在它位于这里。在
python3 -m pip install --upgrade --index-url https://test.pypi.org/simple/ canvas-lms-api
正式回购
最终,它将被更新为“正式的”pypi回购,但现在它位于这里。在
^{pr2}$或者,您可以从中下载源代码和pip安装:
git clone https://github.gatech.edu/omscs-ta/canvas-lms-api
cd canvas-lms-api
pip install .
我还强烈建议您使用.ta文件夹并在主目录中存放一个.yml文件,这样您就可以用任何/所有脚本指向它。在
用法:
获取画布令牌
可在此处找到:Canvas>;Account>;Settings>;Approved Integrations:>;New Access Token。在
获取课程编号
其实有两种方法。在
- 使用此工具查找所有课程,然后使用下面的数字(课程是可选的,您可以稍后设置)
from canvas_lms_api import Canvas
grader = Canvas(base="https://gatech.instructure.com", token=YOUR TOKEN)
grader.GetCourses()
- 登录到画布
- 去你的课程
- 例如:https://gatech.instructure.com/courses/46234
- canvas_course的值为“46234”
获取分配示例
from canvas_lms_api import Canvas
grader = Canvas(base="https://gatech.instructure.com", token=YOUR TOKEN, course=Your Course Number)
grader.GetAssignments()
获取课程用户示例
from canvas_lms_api import Canvas
grader = Canvas(base="https://gatech.instructure.com", token=YOUR TOKEN, course=Your Course Number)
grader.GetCourseUsers()
提交成绩示例
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)
按可排序名称获取StudentID
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中包含“True”,这将允许您获取模块的所有完整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)
- 项目
标签: