Register for InstructureCon25 • Passes include access to all sessions, the expo hall, entertainment and networking events, meals, and extraterrestrial encounters.
Found this content helpful? Log in or sign up to leave a like!
Hello. I am building a GUI app with Python and the tkinter library to get assignment due dates, update them, then push them back out to Canvas. My issue is that when I go to store the dates in a list, the program only stores the last date for all the dates that the user will input, instead of capturing each individually. (screenshot attached)
My code is below (I left out sensitive parts for security reasons). Hopefully it's enough to get a general idea.
I'm using Canvasapi library for my API calls.
def button_clicked():
API_URL = "https://[INSTUTION URL]"
API_KEY = MyToken.secret
canvas_api = Canvas(API_URL, API_KEY)
courseID = uinput.get()
course = canvas_api.get_course(courseID)
global dueDate
dueDate = course.get_course_level_assignment_data()
due_dates_text = ""
for stuff in dueDate:
entry = tk.Entry(assignmentName)
global entry1
entry1 = tk.Entry(dateDue)
global entry2
entry2 = tk.Entry(timeDue)
entry.insert(0, f"{stuff['title']}") #Prints out the assignment names
entry.pack()
### If statements to find the due date and time of the assignments and prints it out
if stuff['due_at'] == None:
entry1.insert(0, "No Due Date")
entry2.insert(0, "No Due Date")
entry1.pack()
entry2.pack()
elif stuff['due_at']:
entry1.insert(0, f"{stuff['due_at'].split('T')[0]}")
entry2.insert(0, f"{stuff['due_at'].split('T')[1]}")
entry1.pack()
entry2.pack()
def pushDueDate():
API_URL = "https://[institution URL]"
API_KEY = MyToken.secret
canvas = Canvas(API_URL, API_KEY)
course = canvas.get_course(uinput.get())
assignment = course.get_assignments()
date = []
time = []
for x in dueDate:
x = entry1.get()
date.append(x)
print(date)
for i in assignment:
update = i.edit(assignment={'due_at': date + 'T' + time + 'Z'})
update
print(date + ' ' + time)
print(update)
Hi @bertscjn,
I'm having a little trouble following your code, but I'm not a python expert by any means (just self-taught with a few different libraries). From my quick look, I think your problem may be around here:
date = []
time = []
for x in dueDate:
x = entry1.get()
date.append(x)
print(date)
for i in assignment:
update = i.edit(assignment={'due_at': date + 'T' + time + 'Z'})
update
print(date + ' ' + time)
print(update)
You're defining date and time as lists, which should have multiple entries. You're then using those lists later on without any kind of index to get an individual date/time (unless there is code that's been stripped out or i'm misreading this).
I hope this helps a bit!
-Chris
Thanks Chris. I appreciate your response! I am working with my sandbox course just to pilot this, and this bug was just discovered! When I call to my course, I get my 3 assignments pulled in with the assignment name, due date, and due time. When I change the due date, whatever the last due date of the 3 assignments is, it applies it to all the due dates.
for instance:
assignment 1 due on 2025-05-10
assignment 2 due on 2025-05-17
assignment 3 due on 2025-05-24
But the data that gets appended to my list is:
assignment 1 due on 2025-05-24
assignment 2 due on 2025-05-24
assignment 3 due on 2025-05-24
Hi @bertscjn,
I believe that's the same issue I was trying to point out.
I think you want something more like:
for index, i in enumerate(assignment):
update = i.edit(assignment={'due_at': date[index] + 'T' + time[index] + 'Z'})
update
print(date[index] + ' ' + time[index])
print(update)
Now this code has a big assumption that the two lists assignment and dueDate are the same length and are in the same order, which I'm not sure would always be true. I'll leave it up to you to verify that's true or test it out on your own. I probably would have used dictionaries with a course-id lookup or something, but there are so many ways to code a project that I hate to pick apart other people's code/ideas too much.
-Chris
To interact with Panda Bot in the Instructure Community, you need to sign up or log in:
Sign In