mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-22 03:31:02 +02:00
Restructuring API a little
This commit is contained in:
parent
9a47915d05
commit
c49568dd34
5 changed files with 191 additions and 108 deletions
|
|
@ -25,7 +25,7 @@ class Loader:
|
|||
self, url, user, metadata, title, comments, kind, tags
|
||||
):
|
||||
|
||||
self.api = Api(url)
|
||||
self.api = Api(url).library()
|
||||
|
||||
self.user = user
|
||||
self.metadata = metadata
|
||||
|
|
@ -57,7 +57,7 @@ class Loader:
|
|||
|
||||
self.metadata.id = id
|
||||
|
||||
self.api.library_add_document(
|
||||
self.api.add_document(
|
||||
document=data, id=id, metadata=self.metadata,
|
||||
user=self.user, kind=self.kind, title=self.title,
|
||||
comments=self.comments, tags=self.tags
|
||||
|
|
|
|||
59
trustgraph-cli/scripts/tg-remove-library-document
Executable file
59
trustgraph-cli/scripts/tg-remove-library-document
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Remove a PDF document from the library
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from trustgraph.api import Api
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_user = 'trustgraph'
|
||||
|
||||
|
||||
def remove_doc(url, user, id):
|
||||
|
||||
api = Api(url).library()
|
||||
|
||||
api.remove_document(user=user, id=id)
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-remove-library-document',
|
||||
description=__doc__,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-u', '--url',
|
||||
default=default_url,
|
||||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-U', '--user',
|
||||
default=default_user,
|
||||
help=f'User ID (default: {default_user})'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--identifier', '--id',
|
||||
required=True,
|
||||
help=f'Document ID'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
remove_doc(args.url, args.user, args.identifier)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Exception:", e, flush=True)
|
||||
|
||||
main()
|
||||
|
||||
|
|
@ -14,9 +14,9 @@ default_user = "trustgraph"
|
|||
|
||||
def show_docs(url, user):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).library()
|
||||
|
||||
docs = api.library_get_documents(user=user)
|
||||
docs = api.get_documents(user=user)
|
||||
|
||||
if len(docs) == 0:
|
||||
print("No documents.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue