cleanup
This commit is contained in:
parent
9a67feefab
commit
652f04461b
20
export.py
20
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
|
||||
|
|
|
@ -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("\"")),
|
||||
|
|
11
test.py
11
test.py
|
@ -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)
|
Loading…
Reference in New Issue