Added support to download canvas webpages #7

Merged
dj346 merged 16 commits from master into master 2022-01-22 10:21:05 -07:00
1 changed files with 20 additions and 0 deletions
Showing only changes of commit 12ba784694 - Show all commits

View File

@ -7,6 +7,8 @@ import string
from canvasapi import Canvas from canvasapi import Canvas
from canvasapi.exceptions import ResourceDoesNotExist, Unauthorized from canvasapi.exceptions import ResourceDoesNotExist, Unauthorized
from singlefile import download_page
import dateutil.parser import dateutil.parser
import jsonpickle import jsonpickle
import requests import requests
@ -198,6 +200,7 @@ def makeValidFolderPath(input_str):
return input_str return input_str
def findCourseModules(course, course_view): def findCourseModules(course, course_view):
modules_dir = os.path.join(DL_LOCATION, course_view.term, modules_dir = os.path.join(DL_LOCATION, course_view.term,
course_view.course_code, "modules") course_view.course_code, "modules")
@ -665,6 +668,18 @@ def exportAllCourseData(course_view):
with open(course_output_path, "w") as out_file: with open(course_output_path, "w") as out_file:
out_file.write(json_str) out_file.write(json_str)
def downloadCourseHTML(api_url, cookies_path):
if(cookies_path == ""):
return
course_dir = DL_LOCATION
if not os.path.exists(course_dir):
os.makedirs(course_dir)
# Downloads the course list.
download_page(api_url + "/courses/", cookies_path, course_dir, "course_list.html")
if __name__ == "__main__": if __name__ == "__main__":
@ -731,6 +746,11 @@ if __name__ == "__main__":
print(" Getting modules and downloading module files") print(" Getting modules and downloading module files")
course_view.modules = findCourseModules(course, course_view) course_view.modules = findCourseModules(course, course_view)
if(COOKIES_PATH):
print(" Downloading course list page")
downloadCourseHTML(API_URL, COOKIES_PATH)
print(" Exporting all course data") print(" Exporting all course data")
exportAllCourseData(course_view) exportAllCourseData(course_view)