def get_exercise(self, exercise): r = requests.get("%sexercises/%d.json" % (self.server, exercise), headers=self.auth, params={"api_version": 7}) data = self.extract_json(r) if not "error" in data: course = Course(int(data["course_id"]), data["course_name"]) exercise = Exercise(course, int(data["exercise_id"]), data["exercise_name"]) exercise.setDownloaded() exercise.setDeadline(data["deadline"], data["deadline"]) return exercise v.log(-1, "Could not find exercise %d" % exercise) return None
def get_course(self, course): if type(course) == int: id = course else: id = course.id r = requests.get("%scourses/%d.json" % (self.server, id), headers=self.auth, params={"api_version": 7}) data = self.extract_json(r) newcourse = Course(int(data["course"]["id"]), data["course"]["name"]) for i in data["course"]["exercises"]: tmp = Exercise(newcourse, int(i["id"]), i["name"]) tmp.setDeadline(i["deadline_description"], i["deadline"]) tmp.attempted = i["attempted"] tmp.completed = i["completed"] tmp.setDownloaded() newcourse.exercises.append(tmp) return newcourse