From 652f04461b5f5313bd3df56409c55c6161d7da32 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Fri, 27 Oct 2023 16:30:16 -0600 Subject: [PATCH] cleanup --- export.py | 20 ++++++++++---------- stuff/singlefile.py | 2 ++ test.py | 11 ----------- 3 files changed, 12 insertions(+), 21 deletions(-) delete mode 100644 test.py diff --git a/export.py b/export.py index 62b44b5..c460839 100644 --- a/export.py +++ b/export.py @@ -21,28 +21,25 @@ COOKIE_JAR = MozillaCookieJar(COOKIES_PATH) COOKIE_JAR.load(ignore_discard=True, ignore_expires=True) -def export_all_course_data(course_view): - json_data = json.dumps(json.loads(jsonpickle.encode(course_view, unpicklable=False)), indent=4) - course_output_dir = os.path.join(DL_LOCATION, course_view.term, course_view.name) +def export_all_course_data(c): + json_data = json.dumps(json.loads(jsonpickle.encode(c, unpicklable=False)), indent=4) + course_output_dir = os.path.join(DL_LOCATION, c.term, c.name) if not os.path.exists(course_output_dir): os.makedirs(course_output_dir) - - course_output_path = os.path.join(course_output_dir, course_view.name + ".json") + course_output_path = os.path.join(course_output_dir, c.name + ".json") with open(course_output_path, "w") as file: file.write(json_data) if __name__ == "__main__": print("Welcome to the Canvas Student Data Export Tool") - print("\nConnecting to Canvas...") - - # Initialize a new Canvas object - canvas = Canvas(API_URL, API_KEY) - print("Creating output directory:", DL_LOCATION) if not os.path.exists(DL_LOCATION): os.makedirs(DL_LOCATION) + print("\nConnecting to Canvas...") + canvas = Canvas(API_URL, API_KEY) + all_courses_views = [] print("Getting list of all courses...") @@ -88,6 +85,9 @@ if __name__ == "__main__": print("Exporting all course data...") export_all_course_data(course_view) + if len(courses) > 1: + print('') + print("Exporting data from all courses combined as all_output.json") # Awful hack to make the JSON pretty. Decode it with Python stdlib json diff --git a/stuff/singlefile.py b/stuff/singlefile.py index 9fa2244..e4e6084 100644 --- a/stuff/singlefile.py +++ b/stuff/singlefile.py @@ -9,6 +9,8 @@ def add_quotes(s): def download_page(url, cookies_path, output_path, output_name_template=""): + # TODO: we can probably safely exclude pages that match the regex r'/external_tools/retrieve\?' + args = [ add_quotes(SINGLEFILE_BINARY_PATH), "--browser-executable-path=" + add_quotes(CHROME_PATH.strip("\"")), diff --git a/test.py b/test.py deleted file mode 100644 index 19a63a0..0000000 --- a/test.py +++ /dev/null @@ -1,11 +0,0 @@ -from http.cookiejar import MozillaCookieJar - -import requests - -s = requests.Session() -cookies = MozillaCookieJar('cookies-canvas-uccs-edu.txt') -cookies.load(ignore_discard=True, ignore_expires=True) -for cookie in cookies: - s.cookies.set(cookie.name, cookie.value) -r = s.get('https://canvas.uccs.edu/api/v1/courses/146797/files/8232290') -print(r.text)