def update_db(semester): response = get_data_from_web(semester) with open(OFFERINGS_FILE, 'w') as fd: fd.write('\t'.join(HEADINGS) + '\n') offerings = Offering.all() offerings = sorted(offerings, key=(lambda offering: (int(offering.semester.code), offering.course, offering.section))) for offering in offerings: if offering.instructors == (None,): # TODO this is stupid instructor_str = 'Instructor Unassigned' else: instructor_str = '; '.join(repr(instructor) for instructor in sorted(offering.instructors, key=(lambda instructor: instructor.last_name))) fd.write('\t'.join(str(field) for field in ( offering.year, offering.season.lower(), offering.department.code, offering.number, offering.section, offering.name, offering.units, instructor_str, '; '.join(repr(meeting) for meeting in sorted(offering.meetings)), '; '.join(sorted(core.code for core in offering.cores)), offering.num_seats, offering.num_enrolled, offering.num_reserved, offering.num_reserved_open, offering.num_waitlisted, )) + '\n') return response
#!/usr/bin/env python3 import re from argparse import ArgumentParser from os.path import exists as file_exists from urllib.parse import quote, unquote, urlencode import requests from bs4 import BeautifulSoup from models import OFFERINGS_FILE, Semester, Meeting, Department, Faculty, Core, Course, Offering from subitizelib import filter_study_abroad COURSE_COUNTS = 'https://counts.oxy.edu/' OFFERINGS = filter_study_abroad(tuple(Offering.all())) HEADINGS = ( 'year', 'season', 'department', 'number', 'section', 'title', 'units', 'instructors', 'meetings', 'cores', 'seats', 'enrolled', 'reserved',