Exemplo n.º 1
0
def main(config):
    configure_logging(config)
    creds = get_credentials(config)
    classroom_service = build("classroom", "v1", credentials=creds)
    admin_reports_service = build("admin", "reports_v1", credentials=creds)
    admin_directory_service = build("admin", "directory_v1", credentials=creds)
    sql = db_generator(config)

    # Get usage
    if config.PULL_USAGE:
        # First get student org unit
        result = OrgUnits(admin_directory_service, sql,
                          config).batch_pull_data()
        org_unit_id = None if result.empty else result.iloc[0].loc["orgUnitId"]

        # Then get usage, loading data from after the last available day.
        usage = StudentUsage(admin_reports_service, sql, config, org_unit_id)
        last_date = usage.get_last_date()
        start_date = last_date + timedelta(days=1) or datetime.strptime(
            config.SCHOOL_YEAR_START, "%Y-%m-%d")
        date_range = pd.date_range(start=start_date,
                                   end=datetime.today()).strftime("%Y-%m-%d")
        usage.batch_pull_data(dates=date_range, overwrite=False)

    # Get guardians
    if config.PULL_GUARDIANS:
        Guardians(classroom_service, sql, config).batch_pull_data()

    # Get guardian invites
    if config.PULL_GUARDIAN_INVITES:
        GuardianInvites(classroom_service, sql, config).batch_pull_data()

    # Get courses
    if config.PULL_COURSES:
        Courses(classroom_service, sql, config).batch_pull_data()

    # Get list of course ids
    if (config.PULL_TOPICS or config.PULL_COURSEWORK or config.PULL_STUDENTS
            or config.PULL_TEACHERS or config.PULL_SUBMISSIONS):
        course_ids = Courses(classroom_service, sql, config).get_course_ids()

    # Get course topics
    if config.PULL_TOPICS:
        Topics(classroom_service, sql, config).batch_pull_data(course_ids)

    # Get CourseWork
    if config.PULL_COURSEWORK:
        CourseWork(classroom_service, sql, config).batch_pull_data(course_ids)

    # Get students and insert into database
    if config.PULL_STUDENTS:
        Students(classroom_service, sql, config).batch_pull_data(course_ids)

    # Get teachers and insert into database
    if config.PULL_TEACHERS:
        Teachers(classroom_service, sql, config).batch_pull_data(course_ids)

    # Get student coursework submissions
    if config.PULL_SUBMISSIONS:
        StudentSubmissions(classroom_service, sql,
                           config).batch_pull_data(course_ids)
Exemplo n.º 2
0
 def test_get_guardians(self):
     self.generic_get_test(Guardians(self.service, self.sql, self.config),
                           GUARDIAN_SOLUTION)