Last active
December 9, 2024 18:24
-
-
Save u8sand/2337723695339d89cf8f0c0f5d1521b4 to your computer and use it in GitHub Desktop.
Validate frictionless datapackage using datapackage-py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Usage: datapackage-validate [datapackage.json] | |
import sys, traceback, logging | |
import datapackage | |
logging.basicConfig(stream=sys.stderr) | |
try: | |
from tqdm.auto import tqdm | |
except ImportError: | |
logging.warn('Install tqdm for progress bar') | |
tqdm = lambda it, *args, **kwargs: it | |
package = datapackage.Package(sys.argv[1]) | |
if not package.valid: | |
logging.error(package.errors) | |
for resource in tqdm(package.resources): | |
logger = logging.getLogger(resource.name) | |
try: | |
for record in tqdm( | |
resource.iter( | |
keyed=True, | |
relations=True, | |
exc_handler=lambda exc, **kwargs: logger.error(f"{exc} {exc.errors}"), | |
), | |
desc=resource.name, | |
): | |
pass | |
except KeyboardInterrupt: | |
raise | |
except Exception as exc: | |
logger.error(f"{exc} {exc.errors}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment