async def sync(loop, db_file, environment):
    """
    Performs all steps to sync Schoology courses
    """
    print(f"Loading {db_file}...")
    AR.init(db_file)
    total_courses = AR.courses().count()
    print(f"Rolling back grading period on {total_courses} courses...")
    async with schoology.Session(environment) as Schoology:
        async with Schoology.Courses as Courses:
            tasks = []
            for course in AR.courses():
                building_code = course.school_code
                title = course.course_description
                course_code = course.school_code + ' ' + course.course_code
                sections = []
                for section in course.active_sections:
                    semester = section.semester
                    grading_period_id = Schoology.GradingPeriods.lookup_id("All Year 2018-2019")
                    if grading_period_id == None:
                        logging.warning("Unable to lookup grading period id for "
                                        f"{section.section_school_code} (Are "
                                        "the grading periods synced with "
                                        "Schoology?)")
                    else:
                        sections.append({
                            'title': section.name,
                            'section_school_code': section.section_school_code,
                            'grading_periods': grading_period_id,
                        })
                tasks.append(
                    Courses.add_update(building_code, title, course_code, sections)
                )
            await utils.task_monitor(tasks)
Ejemplo n.º 2
0
async def sync(loop, db_file, environment):
    """
    Performs all steps to perform Schoology enrollments
    """
    print(f"Loading {db_file}...")
    AR.init(db_file)
    async with schoology.Session(environment) as Schoology:
        async with Schoology.Enrollments as Enrollments:
            len_sections = AR.sections().count()
            print(
                f"Enrolling students and teachers in {len_sections} sections..."
            )
            tasks = []
            for section in AR.sections():
                # enroll the teacher
                section_school_code = section.section_school_code
                teacher_id = section.first_subsection.teacher_id
                tasks.append(
                    Enrollments.add(section_school_code,
                                    teacher_id,
                                    admin=True))
                # enroll the students
                for student in section.active_students:
                    student_id = student.student_id
                    tasks.append(
                        Enrollments.add(section_school_code, student_id))
            await utils.task_monitor(tasks, 30)
Ejemplo n.º 3
0
async def delete_clashing_emails(environment, genesis_ids):
    """
      Looks up who has a clashing email, changes it to a unique, dummy email
      """
    async with schoology.Session(environment) as Schoology:
        async with Schoology.Users as Users:
            results = await Users.csvexport(['mail', 'school_uid'])
            schoology_emails = {}
            for row in csv.reader(results.splitlines()[1:]):
                schoology_emails[str(row[0]).upper()] = str(row[1])
            for genesis_id in genesis_ids:
                student = AR.student_by_id(genesis_id)
                email = student.email
                if email == None or email.upper() not in schoology_emails:
                    print(email)
                    print(f"Unable to determine email for {student}")
                    continue
                clashing_student = AR.student_by_id(
                    schoology_emails[student.email.upper()])
                print(
                    f"{genesis_id} needs the email address {student.email} but "
                    f"{clashing_student.student_id} currently has it.")
                await Users.add_update(
                    school_uid=clashing_student.student_id,
                    name_first=clashing_student.first_name,
                    name_last=clashing_student.last_name,
                    email=clashing_student.student_id + "@monroe.k12.nj.us",
                    role='Student',
                )
Ejemplo n.º 4
0
async def main():
    async with schoology.Session() as Schoology:
        print("Before")
        response = await Schoology.get(
            'https://api.schoology.com/v1/users/72480022')
        user = await response.json()
        print(user)
        user['synced'] = 0
        response = await Schoology.put(
            'https://api.schoology.com/v1/users/72480022', json=user)
        print("After")
        print(await response.json())
Ejemplo n.º 5
0
async def sync(loop, db_file, environment):
    """
    Performs all steps to sync Schoology courses
    """
    print(f"Loading {db_file}...")
    AR.init(db_file)
    total_courses = AR.courses().count()
    print(f"Updating / Adding {total_courses} courses...")
    async with schoology.Session(environment) as Schoology:
        async with Schoology.Courses as Courses:
            tasks = []
            for course in AR.courses():
                building_code = course.school_code
                title = course.course_description
                course_code = course.school_code + ' ' + course.course_code
                sections = []
                for section in course.active_sections:
                    semesters = section.semesters
                    if 'FY' in semesters: # There is only ONE full year
                        grading_periods = [f"{section.school_year} FY"]
                    else: # Others are per building
                        grading_periods = []
                        for semester in semesters:
                            grading_periods.append(f"{section.school_year} "
                                                   f"{section.school_code} "
                                                   f"{semester}")
                    grading_period_ids = []
                    for grading_period in grading_periods:
                        grading_period_id = Schoology.GradingPeriods.lookup_id(
                                grading_period)
                        if grading_period_id == None:
                            logging.warning("Unable to lookup grading period "
                                            "id for "
                                            f"{section.section_school_code} "
                                            "(Are the grading periods synced "
                                            "with Schoology?)")
                        else:
                            grading_period_ids.append(grading_period_id)
                    if grading_period_ids != []:
                        sections.append({
                            'title': section.name,
                            'section_school_code': section.section_school_code,
                            'grading_periods': grading_period_ids,
                        })
                tasks.append(
                    Courses.add_update(building_code, title, course_code, sections)
                )
            await utils.task_monitor(tasks)
Ejemplo n.º 6
0
async def sync(loop, db_file):
    """
    Performs all steps to sync Schoology with a Genesis Database and perform
    some checks
    """
    AR.init(db_file)

    async with schoology.Session("production") as Schoology:
        await add_update_buildings(loop, Schoology)
        (students, teachers, admins, sysadmins, all_ids) = create_user_queries()
        await add_update_users(loop, students, teachers, admins, sysadmins,
            Schoology)
        await delete_users(loop, all_ids, Schoology)
        await add_update_courses(loop, Schoology)
        await add_enrollments(loop, Schoology)
        await check(Schoology)
async def sync(environment, school_year):
    """
    Syncs up Schoology grading periods with Genesis semesters
    """
    async with schoology.Session(environment) as Schoology:
        tasks = []
        # FY (from MTHS)
        cycle = attendance_cycle('FY', 'MTHS', school_year)
        name = f"{school_year} FY"
        tasks.append(
            create_update(Schoology, name, cycle.start_date, cycle.end_date))

        # Everything else can differ by school
        semesters = ['S1', 'S2', 'Q1', 'Q2', 'Q3', 'Q4']
        for school_code in AR.school_codes:
            for semester in semesters:
                cycle = attendance_cycle(semester, school_code, school_year)
                name = f"{school_year} {school_code} {semester}"
                tasks.append(
                    create_update(Schoology, name, cycle.start_date,
                                  cycle.end_date))

        await asyncio.gather(*tasks)
Ejemplo n.º 8
0
async def sync(loop, db_file, environment):
    """
    Performs all steps to sync Schoology buildings

    NOTE: Genesis uses the term 'schools' to refer to the individual
    buildings, Schoology uses buildings. In Schoology there is one school,
    'Monroe Township Schools' and currently 8 buildings (AES, BBS, BES, etc.)
    """
    print(f"Loading {db_file}...")
    AR.init(db_file)
    async with schoology.Session(environment) as Schoology:
        print("Syncing buildings with Schoology...")
        async with Schoology.Buildings as Buildings:
            tasks = []
            for building in AR.schools():
                tasks.append(
                    Buildings.add_update(title=building.school_name,
                                         building_code=building.building_code,
                                         address1=building.school_address1,
                                         address2=building.school_address2,
                                         phone=building.school_office_phone,
                                         website=building.school_url))
            await utils.task_monitor(tasks, 30)
Ejemplo n.º 9
0
async def sync(loop, db_file, environment, force):
    """
    Performs all steps to sync Schoology user accounts
    """
    AR.init(db_file)
    user_sets = create_user_sets()
    async with schoology.Session(environment) as Schoology:
        async with Schoology.Users as Users:
            # Make a dict of genesis_ids -> schoology_uid
            results = await Users.csvexport(['school_uid', 'uid'])
            schoology_users = {}
            for row in csv.reader(results.splitlines()[1:]):
                schoology_users[str(row[0])] = str(row[1])

            # Check for accounts that need to be deleted
            deletes = set(schoology_users.keys()) - user_sets['All']
            len_deletes = len(deletes)
            print(f"Deleting {len_deletes} users...")

            # We have to update EVERYONE because we can't check a student's
            # advisors via the API
            print(f"Adding / Updating {len(user_sets['All'])}...")

            # Sanity checks
            if len_deletes > 25 and not force:
                logging.error(
                    f"Attempting to delete {len_deletes} users, use "
                    "--force if you actually want to perform this action.")
                sys.exit(1)

            tasks = []

            # Perform deletes
            for genesis_id in deletes:
                tasks.append(Users.delete(schoology_users[genesis_id]))

            # Perform adds / updates
            for role, ids in user_sets.items():
                if role == 'Student':
                    for genesis_id in ids:
                        student = AR.student_by_id(genesis_id)
                        advisor_uids = ''
                        if student.counselor_id != '':
                            if student.counselor_id not in schoology_users:
                                logging.warning(f"Counselor "
                                                f"{student.counselor_id} for "
                                                f"{student} not found in "
                                                "Schoology.")
                            else:
                                advisor_uids = schoology_users[
                                    student.counselor_id]
                        tasks.append(
                            Users.add_update(
                                school_uid=student.student_id,
                                name_first=student.first_name,
                                name_last=student.last_name,
                                email=student.email,
                                role=role,
                                advisor_uids=advisor_uids,
                            ))
                elif role != 'All':
                    for genesis_id in ids:
                        teacher = AR.teacher_by_id(genesis_id)
                        tasks.append(
                            Users.add_update(school_uid=teacher.teacher_id,
                                             name_first=teacher.first_name,
                                             name_last=teacher.last_name,
                                             email=teacher.email,
                                             role=role))
            await utils.task_monitor(tasks, 30)