CKAN Data Exgtraction via API

20 views Asked by At

Goal: Extract Berlin Crime Data via CKAN.

Can you anyone help me write a basic api request to validate that you can return the data documented here via CKAN? I am having trouble understanding how to adjust the url when it is not demo data. The goal is to extract berlin crime data : https://daten.berlin.de/tags/ckan and documentation for ckan here: https://docs.ckan.org/en/2.9/api/

current code:

import requests

# CKAN API URL for listing datasets
ckan_url = "http://demo.ckan.org/api/action/package_list"

# Parameters for querying datasets in the "berlin" group
#params = {"group": "berlin"}
params = {"package": "offenedaten"}

# Make the request
response = requests.get(ckan_url, params=params)

# Check if the request was successful (status code 200)
if response.status_code == 200:
    # Extract the list of datasets from the response
    datasets = response.json()["result"]
    print(response.text)
    
    # Print the list of datasets
    # print("List of datasets in the 'berlin' group:")
    # for dataset in datasets:
    #     print("-", dataset)
else:
    print("Error:", response.status_code, response.text)
0

There are 0 answers