def classes(): year = int(request.form['year']) start_month = locale().month_number(request.form['start-month']) start_day = int(request.form['start-day']) last_month = locale().month_number(request.form['last-month']) last_day = int(request.form['last-day']) weekdays = request.form.getlist('days') date_fmt = [b for (a, b) in date_formats() if a == request.form['format']][0] try: start_date = [get(year, start_month, start_day)] except: return "The starting date you specified does not exist." try: last_date = [get(year, last_month, last_day)] except: return "The ending date you specified does not exist." possible_classes, no_classes = sorted_classes(weekdays, start_date, last_date, no_classes=[]) course = schedule(possible_classes, no_classes, show_no=True, fmt=date_fmt) return '<br/>'.join(course)
def results(): semesterYear = request.form['semesterYear'] weekdays = request.form.getlist('days') date_fmt = [b for (a, b) in date_formats() if a == request.form['format']][0] output_fmt = request.form['output'] first_day, last_day, no_classes = parse_registrar_info(semesterYear) possible_classes, no_classes = sorted_classes(weekdays, first_day, last_day, no_classes) course = schedule(possible_classes, no_classes, show_no=True, fmt=date_fmt) if output_fmt == 'plain': return '<br/>'.join(course) else: suffix = '.' + output_fmt templatedir = os.path.dirname(os.path.abspath(__file__)) + '/templates' tf = NamedTemporaryFile(suffix=suffix) output(course, semesterYear, output_fmt, templatedir=templatedir, outfile=tf.name) filename = semesterYear + 'Syllabus' + suffix return send_file(tf.name, attachment_filename=filename, as_attachment=True)
def results(): semester = request.form['semester'] year = request.form['year'] weekdays = request.form.getlist('days') date_fmt = [b for (a, b) in date_formats() if a == request.form['format']][0] output_fmt = request.form['output'] url = make_url(semester, year) possible_classes, no_classes = sorted_classes(weekdays, url) course = schedule(possible_classes, no_classes, show_no=True, fmt=date_fmt) if output_fmt == 'plain': return '<br/>'.join(course) else: suffix = '.' + output_fmt templatedir = os.path.dirname(os.path.abspath(__file__)) + '/templates' tf = NamedTemporaryFile(suffix=suffix) output(course, semester, year, output_fmt, templatedir=templatedir, outfile=tf.name) filename = semester + year + 'Syllabus' + suffix return send_file(tf.name, attachment_filename=filename, as_attachment=True)
import argparse from ricescheduler import make_url, sorted_classes, schedule, output_plain, output_docx parser = argparse.ArgumentParser() parser.add_argument('semester', help='Spring or Fall') parser.add_argument('year', type=int, help='Year as YYYY') parser.add_argument('days', help='String of class days as MTWRF') parser.add_argument('--verbose', action='store_true', help='Show cancelled classes in output') args = parser.parse_args() def check_args(): checks = [] checks.append(set(args.days + 'MTWRF') != set('MTWRF')) checks.append(args.semester.lower() not in ['spring','fall']) if True in checks: print 'Input error in your arguments.' parser.print_help() sys.exit(1) if args.year < 2009: print 'ERROR: The script only works for the years 2009 to the present.' sys.exit(1) check_args() url = make_url(args.semester, str(args.year)) day_index = {'M': 'Monday', 'T': 'Tuesday', 'W': 'Wednesday', 'R': 'Thursday', 'F': 'Friday'} possible_classes, no_classes = sorted_classes([day_index[d] for d in args.days], url) # ricescheduler.output_docx(schedule(possible_classes, no_classes, args.verbose), args.semester, str(args.year), 'output.docx') output_plain(schedule(possible_classes, no_classes, args.verbose))
args = parser.parse_args() def check_args(): checks = [] checks.append(set(args.days + 'MTWRF') != set('MTWRF')) checks.append(args.semester.lower() not in ['spring', 'fall']) if True in checks: print 'Input error in your arguments.' parser.print_help() sys.exit(1) if args.year < 2009: print 'ERROR: The script only works for the years 2019 to the present.' sys.exit(1) check_args() url = make_url(args.semester, str(args.year)) day_index = { 'M': 'Monday', 'T': 'Tuesday', 'W': 'Wednesday', 'R': 'Thursday', 'F': 'Friday' } weekdays = [day_index[d] for d in args.days] possible_classes, no_classes = sorted_classes(weekdays, url) course = schedule(possible_classes, no_classes, show_no=True) print course # ricescheduler.output_docx(schedule(possible_classes, no_classes, args.verbose), args.semester, str(args.year), 'output.docx')