def create_course(): post_body = json.loads(request.data) code = post_body.get('code') name = post_body.get('name') course = Course(code=code, name=name, assignments=[], users=[]) db.session.add(course) db.session.commit() return json.dumps({'success': True, 'data': course.serialize()}), 201
class CourseCrawler: def __init__(self, course_code): self.course = Course(course_code) def crawl(self): pages = self.course.get_pages() for page in pages: messages = page.crawler.get_messages() self.course.update_messages(page.title, messages)
def create_course(): post_body = json.loads(request.data) code = post_body.get('code', '') name = post_body.get('name', '') course = Course(code=code, name=name) db.session.add(course) db.session.commit() data = course.serialize() data['assignments'] = [a.serialize() for a in course.assignments] data['instructors'] = [t.serialize() for t in course.teachers] data['students'] = [s.serialize() for s in course.students] return json.dumps({'success': True, 'data': data}), 201
def get_updates(self): todo_messages = {} for course_code in self.list_courses(): my_course_file = self.get_course_file(course_code) with open(my_course_file, 'r+') as f: published_indices = set([ line[:-1] if line and line[-1] == '\n' else line for line in f.readlines() ]) course = Course(course_code) course_dir = course.messages_dir all_indices = course.messages_list print(all_indices) todo_indices = [ idx for idx in all_indices if idx not in published_indices ] if todo_indices: todo_messages[course_code] = list() for idx in todo_indices: message_address = os.path.join(course_dir, idx) with open(message_address, 'r') as message_file: todo_messages[course_code].append( (idx, message_file.read())) return todo_messages
def create_courses(): # session ?? query ?????????????????? # all ?????????????????? # user ??????? create_users ?? user ?? for user in session.query(User).all(): # ???????????????? for i in range(2): # ???????name ??? 8 ????? course = Course(name=''.join(fake.words(4)), user_id=user.id) session.add(course)
def create_courses(): # session 有个 query 方法用来查询数据,参数为映射类的类名 # all 方法表示查询全部,这里也可以省略不写 # user 就是上一个函数 create_users 中的 user 对象 for user in session.query(User).all(): # 两次循环,对每个作者创建两个课程 for i in range(2): # 创建课程实例,name 的值为 8 个随机汉子 course = Course(name=''.join(fake.words(4)), user_id=user.id) session.add(course)
def add_courses(): info = extract(request) courses = info.get('courses') courses = [ course.upper().replace(' ', '') for course in courses.split(',') ] for course in courses: if not Course.query.filter_by(name=course).first(): db.session.add(Course(name=course)) db.session.commit() return json.dumps({'success': True, 'data': courses}), 201
def menu(): print "Welcome!" while 1: print "1. Add a student" print "2. Delete student data" print "3. Modify student details" print "4. List all students" print "5. Add a course" print "6. Delete course data" print "7. Modify course details" print "8. List all courses" print "9. Enroll student in course" print "10. Show enrollments of a student" print "11. Show enrollments of a course" print "12. Archive old enrollments" print "13. Exit" ch = raw_input("What would you like to do? ") if ch == "1": Student.new_student(students, branches) elif ch == "2": Student.delete_student(students, enrollments) elif ch == "3": Student.modify_student(students) elif ch == "4": Student.list_students(students, branches) elif ch == "5": Course.new_course(courses, branches) elif ch == "6": Course.delete_course(courses, enrollments) elif ch == "7": Course.modify_course(courses) elif ch == "8": Course.list_courses(courses, branches) elif ch == "9": Enrollment.new_enrollment(enrollments, students, courses) elif ch == "10": Enrollment.list_enrollments_stu(enrollments, archived_enrolls, students, courses) elif ch == "11": Enrollment.list_enrollments_cou(enrollments, archived_enrolls, students, courses) elif ch == "12": Enrollment.archive_enrollments(enrollments, archived_enrolls) elif ch == "13": print "\nBye!\n" break else: print "\nNot Valid Choice! Try again!\n" save()
def insert_initial_values(*args, **kwargs): db.session.add( User(net_id='asz33', name='Alanna Zhou', year=2022, major='Computer Science', bio='I like fried bananas.', pic_name='', warm_color='', cool_color='')) db.session.add( User( net_id='ad665', name='Ashneel Das', year=2022, major='Computer Science', bio= 'I love my girlfriend, Katie so much that I could give her fried bananas.', pic_name='', warm_color='', cool_color='')) db.session.add( User(net_id='slh268', name='Sarah Huang', year=2022, major='Chemical Engineering', bio='Yeetaki Mushroomz!', pic_name='', warm_color='', cool_color='')) subjects = requests.get( 'https://classes.cornell.edu/api/2.0/config/subjects.json?roster=FA18' ).json().get('data', '').get('subjects', '') subject_list = [] for s in subjects: subject_list.append(s.get('value', '')) course_list = [] for s in subject_list: courses = requests.get( 'https://classes.cornell.edu/api/2.0/search/classes.json?roster=FA18&subject=' + str(s)).json().get('data', '').get('classes', '') for c in courses: db.session.add( Course(course_subject=c.get('subject', ''), course_num=c.get('catalogNbr', ''), course_name=c.get('titleLong', ''))) db.session.commit()
def create_courses(): for user in session.query(User).all(): for i in range(2): course = Course(name=''.join(fake.words(4)), user_id=user.id) session.add(course)
def crawl(self): for course in Course.list(): cc = CourseCrawler(course) cc.crawl()
def __init__(self): Course.list()
def listen_to(self, course_code): pathlib.Path(self.get_course_file(course_code)).touch() os.makedirs(Course(course_code).data_dir, exist_ok=True)
def __init__(self, course_code): self.course = Course(course_code)