Skip to content

Instantly share code, notes, and snippets.

@FuhuXia
Created October 11, 2023 16:44
Show Gist options
  • Save FuhuXia/da058a7e45f106a5d3efb371d95cd812 to your computer and use it in GitHub Desktop.
Save FuhuXia/da058a7e45f106a5d3efb371d95cd812 to your computer and use it in GitHub Desktop.
bulk delete ckan datasets
#!/usr/bin/env python3
# install ckanapi: https://github.com/ckan/ckanapi#installation
# save dataset id or name into a text file, one dataset per line
# pipenv run python ckan-delete.py dataset-list.txt
import sys
from ckanapi import RemoteCKAN, NotAuthorized
inFile = sys.argv[1]
APIKEY = os.environ['APIKEY']
CKANSERVER = 'https://catalog-prod-admin-datagov.app.cloud.gov/'
catalog = RemoteCKAN(CKANSERVER, apikey=APIKEY)
pkg_ids = []
infile = open(inFile, 'r')
for line in infile:
pkg_ids.append(line.strip())
infile.close()
total=len(pkg_ids)
for count, pkg_id in enumerate(pkg_ids, start=1):
if pkg_id:
print(f"{count}/{total}: {pkg_id}")
catalog.action.package_delete(id=pkg_id)
print('deleted')
print('done!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment