From ccc38c47991de4db03b86c8e50e4ba4a0ae96fe1 Mon Sep 17 00:00:00 2001 From: Tom Morrell Date: Thu, 29 Aug 2024 16:57:26 +0000 Subject: [PATCH] Add pid script --- scripts/get_pid.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 scripts/get_pid.py diff --git a/scripts/get_pid.py b/scripts/get_pid.py new file mode 100644 index 0000000..e0b7b71 --- /dev/null +++ b/scripts/get_pid.py @@ -0,0 +1,27 @@ +import click, os + +from flask.cli import with_appcontext +from invenio_db import db +from invenio_files_rest.models import ObjectVersion +from invenio_utilities_tuw.utils import get_identity_for_user, get_record_service +from invenio_pidstore.models import PersistentIdentifier + +@click.command('delete_pid') +@click.argument('pid', type=str) +@with_appcontext +def get_pid(pid): + """Get pid""" + service = get_record_service() + provider = service.pids.pid_manager._get_provider("doi", "external") + pid_uuid = provider.get(pid_value=pid).object_uuid + query = PersistentIdentifier.query.filter_by( + object_uuid=pid_uuid, + pid_type="recid", + ) + pid_value = query.first().pid_value + + print(pid_value) + + +if __name__=="__main__": + get_pid()