Start of attachment storage.

This commit is contained in:
Jason K. Moore 2020-07-08 09:50:20 -07:00
parent 00ef66f3d6
commit 2c54cbd18b
1 changed files with 43 additions and 15 deletions

View File

@ -1,11 +1,14 @@
from canvasapi import Canvas # built in
import requests
import traceback
import jsonpickle
import json import json
import dateutil.parser
import os import os
import string import string
import traceback
# external
from canvasapi import Canvas
import dateutil.parser
import jsonpickle
import requests
# Canvas API URL # Canvas API URL
API_URL = "" API_URL = ""
@ -13,16 +16,19 @@ API_URL = ""
API_KEY = "" API_KEY = ""
# My Canvas User ID # My Canvas User ID
USER_ID = 0000000 USER_ID = 0000000
# Directory in which to download course information to (will be created if not present) # Directory in which to download course information to (will be created if not
# present)
DL_LOCATION = "./output" DL_LOCATION = "./output"
# List of Course IDs that should be skipped (need to be integers) # List of Course IDs that should be skipped (need to be integers)
COURSES_TO_SKIP = [288290, 512033] COURSES_TO_SKIP = [288290, 512033]
class moduleItemView(): class moduleItemView():
title = "" title = ""
content_type = "" content_type = ""
external_url = "" external_url = ""
class moduleView(): class moduleView():
name = "" name = ""
items = [] items = []
@ -30,17 +36,20 @@ class moduleView():
def __init__(self): def __init__(self):
self.items = [] self.items = []
class pageView(): class pageView():
title = "" title = ""
body = "" body = ""
created_date = "" created_date = ""
last_updated_date = "" last_updated_date = ""
class topicReplyView(): class topicReplyView():
author = "" author = ""
posted_date = "" posted_date = ""
body = "" body = ""
class topicEntryView(): class topicEntryView():
author = "" author = ""
posted_date = "" posted_date = ""
@ -50,6 +59,7 @@ class topicEntryView():
def __init__(self): def __init__(self):
self.topic_replies = [] self.topic_replies = []
class discussionView(): class discussionView():
title = "" title = ""
author = "" author = ""
@ -60,22 +70,33 @@ class discussionView():
def __init__(self): def __init__(self):
self.topic_entries = [] self.topic_entries = []
class submissionView(): class submissionView():
grade = "" grade = ""
raw_score = "" raw_score = ""
total_possible_points = "" total_possible_points = ""
submission_comments = "" submission_comments = ""
user_id = None # integer
attachments = []
class attachmentView():
filename = ""
url = ""
class assignmentView(): class assignmentView():
title = "" title = ""
description = "" description = ""
assigned_date = "" assigned_date = ""
due_date = "" due_date = ""
submissions = {}
submission = None submission = None
def __init__(self): def __init__(self):
self.submission = submissionView() self.submission = submissionView()
class courseView(): class courseView():
term = "" term = ""
course_code = "" course_code = ""
@ -89,6 +110,7 @@ class courseView():
self.announcements = [] self.announcements = []
self.discussions = [] self.discussions = []
def makeValidFilename(input_str): def makeValidFilename(input_str):
# Remove invalid characters # Remove invalid characters
valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits) valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
@ -99,6 +121,7 @@ def makeValidFilename(input_str):
return input_str return input_str
def findCourseModules(course, course_view): def findCourseModules(course, course_view):
modules_dir = DL_LOCATION + "/" + course_view.term + "/" + course_view.course_code + "/modules" modules_dir = DL_LOCATION + "/" + course_view.term + "/" + course_view.course_code + "/modules"
@ -263,12 +286,17 @@ def findCourseAssignments(course):
print(submissions) print(submissions)
for submission in submissions: for submission in submissions:
print(submission) print(submission)
sub_view = submissionView()
try: try:
submission.attachments submission.attachments
except AttributeError: except AttributeError:
print('No attachements') print('No attachments')
else: else:
for attachment in submission.attachments: for attachment in submission.attachments:
attach_view = attachmentView()
attach_view.url = attachment.url
attach_view.filename = attachment.filename
sub_view.attachments.append
print(attachment["url"]) print(attachment["url"])
# Get my user"s submission object # Get my user"s submission object