#!/usr/bin/env python3
# @file cmu-course-api
# @brief Downloads schedule data for a specific semester, including course
#        meeting times, course descriptions, pre/corequisites, and so on.
#        Output is parsed into a single JSON output file.
#
#        USAGE: cmu-course-api [SEMESTER] [OUTFILE]
#
# @author Justin Gallagher (jrgallag@andrew.cmu.edu)
# @since 2015-11-08


import cmu_course_api
import json
import sys


# Constants
USAGE = 'USAGE: cmu-course-api [SEMESTER] [OUTFILE]'


# Verify arguments
if not (len(sys.argv) == 3):
    print(USAGE)
    sys.exit()

semester = sys.argv[1]
outpath = sys.argv[2]

if semester not in ['S', 'M1', 'M2', 'F']:
    print("Requested quarter is not one of ['S', 'M1', 'M2', 'F']")
    sys.exit()

# Get the data
print('Scottylabs CMU Course-API')

print('Getting data...')
data = cmu_course_api.get_course_data(semester)

print('Writing data...')
with open(outpath, 'w') as outfile:
    json.dump(data, outfile)

print('Done!')
