MetadataExtractorClient
The snippet can be accessed without any authentication.
Authored by
Benedikt Heinrichs
Edited
snippetfile1.txt 1.21 KiB
from pathlib import Path
import requests
from rdflib.graph import Graph, ConjunctiveGraph
import os
import uuid
import magic
apiUrl = "http://127.0.0.1:36541/"
foldersToScan = [
"{{FolderWithFile}}"
]
for folder in foldersToScan:
pathFolder = Path(folder)
name = pathFolder.name
for path in pathFolder.rglob("*"):
g = ConjunctiveGraph()
file_dict = {}
fileCount = 0
print(path.name)
if os.path.isfile(str(path)):
filePointer = open(str(path), "rb")#, encoding="utf-8", errors="ignore")
file_dict[str(path)] = (str(path), filePointer, magic.from_file(str(path), mime=True))
fileCount += 1
response = requests.post(apiUrl, files=file_dict)
jsonResponse = response.json()
for response in jsonResponse:
for entry in response:
g.parse(data=response[entry][0]["metadata"], format="trig")
for key in file_dict:
file_dict[key][1].close()
outName = path.name + ".out.trig"
print("Write output to: " + outName)
with open(outName, "w", encoding="utf-8") as outfile:
outfile.write(g.serialize(format="trig", encoding="utf-8").decode("utf-8"))
Please register or sign in to comment