@webapi.route('/latest/licenses.json')
@log_application_errors
def app_licenses_json():
    with db_connect(current_app.config['DATABASE_URL']) as conn:
        with db_cursor(conn) as db:
            set = read_latest_set(db, 'openaddresses', 'openaddresses')
            runs = read_completed_runs_to_date(db, set.id)

    licenses = defaultdict(list)
    
    for run in runs:
        run_state = run.state or {}
        source = os.path.relpath(run.source_path, 'sources')
    
        attribution = None
        if run_state.get('attribution required') != 'false':
            attribution = run_state.get('attribution name')
        
        key = run_state.get('license'), attribution
        licenses[key].append((source, run_state.get('website')))
        
    licenses = [dict(license=lic, attribution=attr, sources=sorted(srcs))
                for ((lic, attr), srcs) in sorted(licenses.items())]
    
    return jsonify(licenses=licenses)
dataset/ETHPy150Open openaddresses/machine/openaddr/ci/webapi.py/app_licenses_json/original