def get_course_list(user_auth, user_email): courselist = [] service = create_service(user_auth, _API_NAME, _API_VERSION, _SCOPES, user_email=user_email) res = service.courses().list().execute() #print(res.toString()) if 'courses' in res: for course in res['courses']: cw = get_coursework_list(user_auth, user_email, course['id'], ser=service) annou = get_announcements(user_auth, user_email, course['id'], ser=service) coursejson = DigiJsonBuilder.create_course(course['name'], course['id'], [user_email], announcements=annou, coursework=cw) courselist.append(coursejson) return courselist
def get_course(user_auth, user_email, course_id, ser=None): service = create_service( user_auth, _API_NAME, _API_VERSION, _SCOPES, user_email=user_email) if ser == None else ser course = service.courses().get(id=course_id).execute() coursejson = DigiJsonBuilder.create_course(course['name'], course_id, [user_email], announcements=[], coursework=[]) otherfromgoogle = { 'section': course['section'] if 'section' in course else None, 'room': course['room'] if 'room' in course else None, 'courseState': course['courseState'] if 'courseState' else None, 'teacherGroupEmail': course['teacherGroupEmail'] if 'teacherGroupEmail' in course else None, 'courseDescription': course['descriptionHeading'] if 'descriptionHeading' in course else None } coursejson.update(otherfromgoogle) mats = _get_materials_from_json(course['courseMaterialSets'] if 'courseMaterialSets' in course else None) coursejson.update({'materialSets': mats}) return coursejson
def submit_assignment(user_auth, user_email, course_id, submission, coursework_id, ser=None): # assumes submission is json object from DigiJsonBuilder.create_file() service = create_service( user_auth, _API_NAME, _API_VERSION, _SCOPES, user_email=user_email) if ser == None else ser # user_email is their ID # as user fins the student submission object usl = service.courseWork().studentSubmissions().list( courseId=course_id, courseWorkId=coursework_id, userId='me').execute() us = usl['studentSubmissions'][0] subid = us['id'] # as user attach submission attach = GDriveJsonBuilder.add_file_attachment(submission['driveID']) umod = service.courseWork().studentSubmissions().modifyAttachments( courseId=course_id, courseWorkId=coursework_id, id=subid, body=attach).execute() # if attachment was successful (we just assume this cause digilearn babyy) # submit assignment sub = service.courseWork().studentSubmissions().turnIn( courseId=course_id, courseWorkId=coursework_id, id=subid).execute() return sub
def get_materials(user_auth, user_email, course_id, coursework_id, ser=None): service = create_service( user_auth, _API_NAME, _API_VERSION, _SCOPES, user_email=user_email) if ser == None else ser cw = service.courses().courseWork().get(courseId=course_id, id=coursework_id).execute() matlist = _get_materials_from_json(cw) return matlist
def get_coursework_list(user_auth, user_email, course_id, ser=None): service = create_service(user_auth, _API_NAME, _API_VERSION, _SCOPES, user_email=user_email) if ser == None else ser gcwlist = service.courses().courseWork().list(courseId=course_id).execute() cwlist = [] if 'courseWork' in gcwlist: for coursework in gcwlist['courseWork']: cwid = coursework['id'] cwjson = get_coursework(user_auth, user_email, course_id, cwid, service) cwlist.append(cwjson) return cwlist
def get_announcements(user_auth, user_email, course_id, ser=None): service = create_service(user_auth, _API_NAME, _API_VERSION, _SCOPES, user_email=user_email) if ser == None else ser gannoulist = service.courses().announcements().list(courseId=course_id, announcementStates='PUBLISHED').execute() anlist = [] mode = None if 'announcements' in gannoulist: for gan in gannoulist["announcements"]: anid = gan['id'] antext = gan['text'] if 'text' in gan else None anmats = _get_materials_from_json(gan) if 'materials' in gan else None anctime = gan['creationTime'] if 'creationTime' in gan else None anstu = [user_email] anou = DigiJsonBuilder.create_announcement(anid, antext, anmats, anctime, mode, anstu) anlist.append(anou) return anlist
def get_coursework(user_auth, user_email, course_id, coursework_id, ser=None): service = create_service(user_auth, _API_NAME, _API_VERSION, _SCOPES, user_email=user_email) if ser == None else ser cw = service.courses().courseWork().get(courseId=course_id, id=coursework_id).execute() cwid = cw['id'] title = cw['title'] desc = cw['description'] if 'description' in cw else None mats = get_materials(user_auth, user_email, course_id, cwid, service) ctime = cw['creationTime'] ddate = cw['dueDate'] if 'dueDate' in cw else None dtime = cw['dueTime'] if 'dueTime' in cw else None wtype = cw['workType'] if 'workType' in cw else None dets = cw['multipleChoiceQuestion'] if 'multipleChoiceQuestion' in cw else None pts = cw['maxPoints'] if 'maxPoints' in cw else None cwjson = DigiJsonBuilder.create_coursework(cwid, title, desc, mats, ctime, ddate, dtime, wtype, None, [user_email], dets) if pts != None: cwjson.update({"maxPoints": pts}) return cwjson