def check_ils_booking(gadget_url_base):
    """
    Checks the session and returns when the lab is free (in UTC). If None is returned, it means that there is no ongoing session so they can use the lab.
    """
    ils_student_id = extract_ils_id(request.args.get('ils_student_url'))
    ils_teacher_id = extract_ils_id(request.args.get('ils_teacher_url'))

    # BOOKING_URL = url_for('.mock_golabz_booking_service', _external=True)
    BOOKING_URL = 'http://www.golabz.eu/rest/lab-booking/retrieve.json'

    try:
        r = requests.get(BOOKING_URL, headers = {
            'Cache-Control': 'no-cache',
            'Pragma': 'no-cache',
        })
        r.raise_for_status()
        booking_slots = r.json()
    except Exception as e:
        traceback.print_exc()
        # We can not stop students using the labs if the service is temporarily down
        return None

    affected_ilss = []
    oldest_affected_endtime = datetime.datetime.utcnow()
    for booking_slot in booking_slots:
        is_current_lab = False
        for lab_app in booking_slot.get('lab_apps', []):
            lab_url = lab_app.get('app_url', '')
            if lab_url.startswith(gadget_url_base):
                is_current_lab = True
                break

        if not is_current_lab:
            continue
        
        start_time_str = booking_slot.get('start_time', '2000-01-01T00:00:00')
        end_time_str = booking_slot.get('end_time', '2000-01-01T00:00:00')
        FORMAT = '%Y-%m-%dT%H:%M:%S'

        try:
            start_time = datetime.datetime.strptime(start_time_str, FORMAT)
            end_time = datetime.datetime.strptime(end_time_str, FORMAT)
        except __HOLE__:
            traceback.print_exc()
            continue

        now = datetime.datetime.utcnow()
        if end_time > now > start_time:
            ils_id = extract_ils_id(booking_slot.get('ils_url')) or 'does.not.exist'
            if end_time > oldest_affected_endtime:
                oldest_affected_endtime = end_time
            affected_ilss.append(ils_id)

    if affected_ilss:
        for affected_ils_id in affected_ilss:
            if affected_ils_id in (ils_student_id, ils_teacher_id):
                return None
        # If there are affected ILS, but we're not part of them, we're not authorized
        return oldest_affected_endtime
    else:
        # If there is no affected ILS, it doesn't matter if we're in the group or not
        return None
dataset/ETHPy150Open gateway4labs/labmanager/labmanager/views/opensocial.py/check_ils_booking