Example #1
0
def _get_v2_by_sids_list(up_to_100_sids,
                         term_id,
                         as_of,
                         with_registration,
                         with_contacts,
                         mock=None):
    """Collect SIS Student Profile data for up to 100 SIDs at a time.

    The SIS 'list' request does not return studentAttributes, ethnicities, or gender. (In other words, 'inc-attr',
    'inc-dmgr', and 'inc-gndr' options are ignored.) As a practical matter, registrations should only be requested
    in combination with a 'term-id' parameter. No registrations outside that term will be returned, and will have
    to be filled in by some other API call.
    """
    id_list = ','.join(up_to_100_sids)
    params = {
        'id-list': id_list,
        'affiliation-status': 'ALL',
        'inc-acad': True,
        'inc-cntc': with_contacts,
        'inc-completed-programs': True,
        'inc-inactive-programs': True,
    }
    if term_id:
        params['term-id'] = term_id
    if as_of:
        params['as-of-date'] = as_of
    if with_registration:
        params['inc-regs'] = True
    url = http.build_url(app.config['STUDENT_API_URL'] + '/list', params)
    with mock(url):
        return authorized_request_v2(url)
Example #2
0
def _get_enrollments(cs_id, term_id, mock=None):
    query = {
        'term-id': term_id,
        'page-size': 50,
    }
    url = http.build_url(app.config['ENROLLMENTS_API_URL'] + '/' + str(cs_id),
                         query)
    with mock(url):
        return authorized_request(url)
Example #3
0
def xkcd():
    try:
        url = http.build_url(
            f'https://xkcd.com/{randint(1, 2427)}/info.0.json')
        json = http.request(url).json()
    except Exception:
        json = {
            'alt': '40% of OpenBSD installs lead to shark attacks.',
            'img': 'https://imgs.xkcd.com/comics/success.png',
        }
    return tolerant_jsonify(json)
Example #4
0
def _get_v2_registrations_demog(sid, as_of=None, with_demog=True, mock=None):
    params = {
        'affiliation-status': 'ALL',
        'inc-regs': True,
    }
    if as_of:
        params['as-of-date'] = as_of
    if with_demog:
        params.update({
            'inc-dmgr': True,
            'inc-gndr': True,
        })
    url = http.build_url(app.config['STUDENT_API_URL'] + f'/{sid}', params)
    with mock(url):
        return authorized_request_v2(url)
Example #5
0
def get_bookings_for_date(date):
    bookings = []
    date_str = date.strftime('%Y-%m-%d')
    url = http.build_url(
        f"{app.config['YCBM_BASE_URL']}/bookings",
        {
            'fields':
            ','.join([
                'id',
                'title',
                'startsAt',
                'endsAt',
                'answers',
                'answers.code',
                'answers.string',
                'cancelled',
                'calendars',
                'calendars.calendarId',
                'calendars.targetCalendar',
                'cancellationReason',
                'teamMember',
                'teamMember.name',
                'teamMember.id',
                'teamMember.email',
            ]),
            'jumpToDate':
            date_str,
        },
    )
    response = get_authorized_response(url)
    # YCBM API pagination seems a little wobbly as far as how it orders bookings, so we cast a wide net and request more pages
    # as long as any bookings on the current page have the date of interest. This conservative approach means we'll end up with
    # extra appointments outside our date range, so higher-level code should use booking ids to screen out duplicates.
    while response and hasattr(response, 'json'):
        feed = response.json()
        if not len(feed) or next(
            (b for b in feed if b.get('startsAt', '').startswith(date_str)),
                None) is None:
            break
        bookings += feed
        next_url = response.links.get('next', {}).get('url')
        if not next_url:
            break
        response = get_authorized_response(next_url)
    return bookings
Example #6
0
def _get_v2_single_student(sid, term_id=None, as_of=None):
    params = {
        'affiliation-status': 'ALL',
        'inc-acad': True,
        'inc-attr': True,
        'inc-cntc': True,
        'inc-completed-programs': True,
        'inc-inactive-programs': True,
        'inc-dmgr': True,
        'inc-gndr': True,
        'inc-regs': True,
    }
    # If 'term-id' is not specified, the 'inc-regs' parameter will pull in all registrations.
    # This will slow responses down considerably.
    if term_id:
        params['term-id'] = term_id
    if as_of:
        # In format '2018-12-01'.
        params['as-of-date'] = as_of
    url = http.build_url(app.config['STUDENT_API_URL'] + f'/{sid}', params)
    return authorized_request_v2(url)
Example #7
0
def _get_registrations(cs_id, mock=None):
    url = http.build_url(app.config['STUDENT_API_URL'] + '/' + str(cs_id) + '/registrations')
    with mock(url):
        return authorized_request(url)
Example #8
0
def _get_student(cs_id, mock=None):
    url = http.build_url(app.config['STUDENT_API_URL'] + '/' + str(cs_id) + '/all')
    with mock(url):
        return authorized_request(url)
Example #9
0
def _get_cal1card_photo(uid, mock=None):
    url = http.build_url(app.config['CAL1CARD_PHOTO_API_URL'], {'uid': uid})
    with mock(url):
        return http.request(url,
                            auth=cal1card_api_auth(),
                            timeout=app.config['CAL1CARD_PHOTO_API_TIMEOUT'])
Example #10
0
def _get_degree_progress(cs_id, mock=None):
    url = http.build_url(app.config['DEGREE_PROGRESS_API_URL'],
                         {'EMPLID': cs_id})
    with mock(url):
        return http.request(url, auth=cs_api_auth(), log_404s=False)
Example #11
0
def build_url(path, query=None):
    working_url = app.config['CANVAS_HTTP_URL'] + path
    return http.build_url(working_url, query)