-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas_buddy.py
executable file
·95 lines (70 loc) · 2.61 KB
/
canvas_buddy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /usr/bin/env python3.5
"""CanvasBuddy
Canvas command line tool for students
With this application you can:
View courses
View grades
View assignments
All from your command line
Author: Jeff Bell
"""
import canvas
class Colors:
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
BLUE = "\033[34m"
RESET = "\033[0m"
class CanvasBuddy:
def select_course(self):
"""Select a course from the dashboard favorites"""
courses_json = canvas.get_favorite_courses()
selection = -1
while selection <= 0 or selection > len(courses_json):
try:
print(Colors.YELLOW, "Please select a course below...",
Colors.RESET)
self.show_courses(courses_json)
selection = int(input(">> "))
except(ValueError):
print(Colors.RED, "You must enter a number below!", Colors.RESET)
selection_string = "You selected: {}".format(selection)
print(selection_string)
course_id = courses_json[selection - 1]["id"]
return course_id
def show_courses(self, courses_json):
"""Show an enumerated list of favorited courses"""
print(Colors.GREEN, "🎓 Your Courses 🎓", Colors.RESET)
course_count = 1
for course in courses_json:
name = course["name"]
format_string = "{}{}.{} {}".format(Colors.BLUE,
course_count, Colors.RESET, name)
course_count += 1
print(format_string)
def show_assignments(self, course_id):
"""Show the grades for all assignments"""
print(Colors.BLUE, "📓 Grades 📓", Colors.RESET)
assignments_json = canvas.get_assignments(course_id)
for assignment in assignments_json:
name = str(assignment["name"])
points_possible = str(assignment["points_possible"])
assignment_id = assignment["id"]
submissions_json = canvas.get_submissions(course_id, assignment_id)
grade = str(submissions_json["grade"])
format_string = "{:<50.45} {}{:<6.5}{}/{:>6.6}".format(name,
Colors.GREEN, grade, Colors.RESET, points_possible)
print(format_string)
"""Begin script code"""
canvas_buddy = CanvasBuddy()
run = True
while run:
course = canvas_buddy.select_course()
canvas_buddy.show_assignments(course)
try:
print("Continue? (y/n)")
selection = str(input(">> ")).lower()
if selection != "y":
run = False
except(ValueError):
pass