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。在

获取课程编号

其实有两种方法。在

  1. 使用此工具查找所有课程,然后使用下面的数字(课程是可选的,您可以稍后设置)
from canvas_lms_api import Canvas
grader = Canvas(base="https://gatech.instructure.com", token=YOUR TOKEN)
grader.GetCourses()
  1. 登录到画布

获取分配示例

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)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java随机填充2d数组   java运行时。getRuntime。带有长参数的exec(cmd)   java Minecraft无法放置自定义背景   java AChartEngine YAxis自定义标签区域边距和图表值为字符串?   泛型类的java类型安全错误   整数的java符号等价物。toBinaryString方法?   Java中数组列表的数组   java WebView应用程序在谷歌登录后显示空白屏幕   java从backback中删除特定片段   如果服务器不支持使用的协议,java JSSE是否实现回退?   java Sonarqube正在进行核心漏洞查找。如何解决   javajavax。jcr。UnsupportedPositionOperationException:testVersionable处的节点不可版本化   java在安卓中每隔X小时运行一次文件/函数,无需打开应用程序   java如何为磁盘持久性配置BigMemory?   java BufferWriter不转换383以上的整数   Java7交集类型:规范具体说明了什么?   Java:CollectionHow创建多列   java如何检测运算符的空白   java问题:在firebase中为导航栏中的第二个表单提交数据第一个表单工作正常。实际isse是连接Mainactivity中的另一个活动