def get_usable_bounding_boxes(nominal_boxes, cfg):
    FLICKR_PUBLIC = get_secret('flickr_api_key')
    FLICKR_SECRET = get_secret('flickr_api_secret')
    flickr = FlickrAPI(FLICKR_PUBLIC, FLICKR_SECRET, format='parsed-json')
    boxes = []
    working = nominal_boxes.copy()
    license = '1,2,3,4,5,6,7,8,9,10'
    extras = 'description,license,date_upload,date_taken,original_format,'
    extras += 'last_update,geo,tags, machine_tags, o_dims, media,'
    extras += 'url_m,url_n,url_z,url_c,url_l,url_o'
    city_total = 0
    while (len(working) > 0):
        box = working.pop()
        temp = list(map(str, box))
        str_box = ','.join(temp)
        box_area = est_area(box)
        divide_flag = False
        if (box_area > cfg['max_area']):
            total_imgs = (- 1)
            divide_flag = True
        else:
            time.sleep(cfg['time_delay'])
            try:
                box_pics = flickr.photos.search(privacy_filter=PRIVACY_FILTER, bbox=str_box, content_type=CONTENT_TYPE, has_geo=HAS_GEO, geo_context=GEO_CTX, license=license, extras=extras, per_page=cfg['page_size'])
                total_imgs = int(box_pics['photos']['total'])
                divide_flag = ((total_imgs >= cfg['density_limit']) and (box_area > cfg['min_area']))
            except FlickrError as err:
                print(f'Error retrieving intitial page for bounding box {bbox}')
                print(f'{err}')
        if divide_flag:
            new_box_1 = box.copy()
            new_box_2 = box.copy()
            if ((box[2] - box[0]) > (box[3] - box[1])):
                border = ((box[0] + box[2]) / 2)
                new_box_1[2] = border
                new_box_2[0] = border
            else:
                border = ((box[1] + box[3]) / 2)
                new_box_1[3] = border
                new_box_2[1] = border
            working.append(new_box_1)
            working.append(new_box_2)
        elif (total_imgs == 0):
            continue
        else:
            city_total += total_imgs
            boxes.append(box)
    print(city_total)
    return boxes
def get_usable_bounding_boxes(nominal_boxes, cfg):
    FLICKR_PUBLIC = get_secret('flickr_api_key')
    FLICKR_SECRET = get_secret('flickr_api_secret')
    flickr = FlickrAPI(FLICKR_PUBLIC, FLICKR_SECRET, format='parsed-json')
    boxes = []
    working = nominal_boxes.copy()
    license = '1,2,3,4,5,6,7,8,9,10'
    extras = 'description,license,date_upload,date_taken,original_format,'
    extras += 'last_update,geo,tags, machine_tags, o_dims, media,'
    extras += 'url_m,url_n,url_z,url_c,url_l,url_o'
    city_total = 0
    while (len(working) > 0):
        box = working.pop()
        temp = list(map(str, box))
        str_box = ','.join(temp)
        box_area = est_area(box)
        divide_flag = False
        if (box_area > cfg['max_area']):
            total_imgs = (- 1)
            divide_flag = True
        else:
            time.sleep(cfg['time_delay'])
            try:
                box_pics = flickr.photos.search(privacy_filter=PRIVACY_FILTER, bbox=str_box, content_type=CONTENT_TYPE, has_geo=HAS_GEO, geo_context=GEO_CTX, license=license, extras=extras, per_page=cfg['page_size'])
                total_imgs = int(box_pics['photos']['total'])
                divide_flag = ((total_imgs >= cfg['density_limit']) and (box_area > cfg['min_area']))
            except FlickrError as err:
                print(f'Error retrieving intitial page for bounding box {bbox}')
                print(f'{err}')
        if divide_flag:
            new_box_1 = box.copy()
            new_box_2 = box.copy()
            if ((box[2] - box[0]) > (box[3] - box[1])):
                border = ((box[0] + box[2]) / 2)
                new_box_1[2] = border
                new_box_2[0] = border
            else:
                border = ((box[1] + box[3]) / 2)
                new_box_1[3] = border
                new_box_2[1] = border
            working.append(new_box_1)
            working.append(new_box_2)
        elif (total_imgs == 0):
            continue
        else:
            city_total += total_imgs
            boxes.append(box)
    print(city_total)
    return boxes