Skip to content

Commit

Permalink
use Json source to create actions
Browse files Browse the repository at this point in the history
  • Loading branch information
stefangrotz committed Dec 10, 2023
1 parent 89b7363 commit bcd973c
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions actions/create-api-files.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import json

# List of endpoints with names
endpoints = [
{"name": "OpenData_HRO", "url": "https://www.opendata-hro.de/api/3/"},
{"name": "Offene_Daten_Moers", "url": "https://www.offenesdatenportal.de/api/3/"},
{"name": "Open_Data_Koeln", "url": "https://www.offenedaten-koeln.de/api/3/"},
# ... include all other endpoints with their names here ...
]

# Function to create the API structure with dynamic description
def create_api_structure(url,name):
return {
Expand All @@ -17,7 +9,6 @@ def create_api_structure(url,name):
"description": f"The CKAN API for accessing and managing datasets from {name}. Use a limit:50 as a parameter for queries to avoid too long responses!",
"version": "1.0.0"
},
# ... include other necessary fields here ...
"servers": [{"url": url}],
"paths": {
"/action/package_search": {
Expand Down Expand Up @@ -261,6 +252,21 @@ def create_api_file(endpoint_info):
json.dump(api_structure, file, indent=4)
print(f"Created file: {file_name}")

# Function to truncate URL to 'api/3/'
def truncate_url(url):
index = url.find('api/3/')
return url[:index + 6] if index != -1 else url

# Load the JSON data from the file
with open('query.json', 'r') as file:
portals = json.load(file)

# Prepare a list of endpoints using the loaded JSON data
endpoints = [
{"name": portal["portalLabel"], "url": truncate_url(portal["hasApiEndpoint"])}
for portal in portals if "hasApiEndpoint" in portal
]

# Create an API file for each endpoint
for endpoint in endpoints:
create_api_file(endpoint)
Expand Down

0 comments on commit bcd973c

Please sign in to comment.