<reponame>tophermckee/python_lca_data
import sys
sys.path.append("..")
from util.utilities import *

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(levelname)s - %(message)s',
    datefmt='%B-%d-%Y %H:%M:%S',
    filename=f"../logs/{Path(__file__).stem}.log",
    filemode='w'
)

def update_course_grades():
    course_grades = sr_api_pull(
        'course-grades',
        parameters = {
            'active': 1,
            'school_ids': 15,
            'expand': 'term_bin.term, student, course',
        }
    )

    main_sheet = return_spreadsheet('LCA Credit & Schedule Tool', 'full_course_grades')

    output = [[
        'SIS ID',
        'Name',
        'Term Bin',
        'Course',
        'Credits',
        'Score'
    ]]

    for course_grade in course_grades:
        if course_grade['student']['active'] == '1' and course_grade['student']['school_id'] == '15':
            output.append([
                course_grade['student']['sis_id'],
                course_grade['student']['display_name'],
                f"{course_grade['term_bin']['term']['short_name']} {course_grade['term_bin']['short_name']}",
                course_grade['course']['display_name'],
                course_grade['course']['credits'],
                course_grade['score']
            ])

    main_sheet.batch_clear(['A1:F'])
    main_sheet.update('A1', output, value_input_option='USER_ENTERED')

if __name__ == '__main__':
    update_course_grades()