2025-04-24 18:57:33 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
import json
|
|
|
|
|
import sys
|
|
|
|
|
import base64
|
2025-05-04 22:26:19 +01:00
|
|
|
import time
|
2025-04-24 18:57:33 +01:00
|
|
|
|
|
|
|
|
url = "http://localhost:8088/api/v1/"
|
|
|
|
|
|
|
|
|
|
############################################################################
|
|
|
|
|
|
2025-05-04 22:26:19 +01:00
|
|
|
id = "http://trustgraph.ai/doc/9fdee98b-b259-40ac-bcb9-8e82ccedeb04"
|
2025-04-24 18:57:33 +01:00
|
|
|
|
2025-05-04 22:26:19 +01:00
|
|
|
with open("docs/README.cats", "rb") as f:
|
|
|
|
|
doc = base64.b64encode(f.read()).decode("utf-8")
|
2025-04-24 18:57:33 +01:00
|
|
|
|
|
|
|
|
input = {
|
2025-05-04 22:26:19 +01:00
|
|
|
"operation": "add-document",
|
|
|
|
|
"document-metadata": {
|
2025-04-24 18:57:33 +01:00
|
|
|
"id": id,
|
2025-05-04 22:26:19 +01:00
|
|
|
"time": int(time.time()),
|
|
|
|
|
"kind": "text/plain",
|
|
|
|
|
"title": "Mark's cats",
|
|
|
|
|
"comments": "Test doc taken from the TrustGraph repo",
|
2025-04-24 18:57:33 +01:00
|
|
|
"metadata": [
|
|
|
|
|
{
|
|
|
|
|
"s": {
|
|
|
|
|
"v": id,
|
|
|
|
|
"e": True,
|
|
|
|
|
},
|
|
|
|
|
"p": {
|
|
|
|
|
"v": "http://www.w3.org/2000/01/rdf-schema#label",
|
|
|
|
|
"e": True,
|
|
|
|
|
},
|
|
|
|
|
"o": {
|
|
|
|
|
"v": "Mark's pets", "e": False,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"s": {
|
|
|
|
|
"v": id,
|
|
|
|
|
"e": True,
|
|
|
|
|
},
|
|
|
|
|
"p": {
|
|
|
|
|
"v": 'https://schema.org/keywords',
|
|
|
|
|
"e": True,
|
|
|
|
|
},
|
|
|
|
|
"o": {
|
|
|
|
|
"v": "cats", "e": False,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
"user": "trustgraph",
|
2025-05-04 22:26:19 +01:00
|
|
|
"tags": ["mark", "cats"],
|
|
|
|
|
},
|
|
|
|
|
"content": doc,
|
2025-04-24 18:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp = requests.post(
|
|
|
|
|
f"{url}librarian",
|
|
|
|
|
json=input,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
print(resp.text)
|
|
|
|
|
resp = resp.json()
|
|
|
|
|
|
|
|
|
|
print(resp)
|
|
|
|
|
|
|
|
|
|
if "error" in resp:
|
|
|
|
|
print(f"Error: {resp['error']}")
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
# print(resp["response"])
|
|
|
|
|
print(resp)
|
|
|
|
|
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
############################################################################
|
|
|
|
|
|