Skip to content
Permalink
Browse files
fix: add folder independence
  • Loading branch information
subotic committed Mar 22, 2019
1 parent 7f79530 commit 24609374fa9881467a6fa9f7b6924daec9534ddf
Showing with 19 additions and 12 deletions.
  1. +5 −2 knora/create_ontology.py
  2. +14 −10 knora/knora.py
@@ -1,3 +1,4 @@
import os
from typing import List, Set, Dict, Tuple, Optional
from pprint import pprint
import argparse
@@ -17,12 +18,14 @@ def main():

args = parser.parse_args()

current_dir = os.path.dirname(os.path.realpath(__file__))

# let's read the schema for the ontology definition
if args.lists:
with open('knora-schema-lists.json') as s:
with open(os.path.join(current_dir, 'knora-schema-lists.json')) as s:
schema = json.load(s)
else:
with open('knora-schema.json') as s:
with open(os.path.join(current_dir, 'knora-schema.json')) as s:
schema = json.load(s)

# read the ontology definition
@@ -92,9 +92,9 @@ class knora:
def __init__(self, server: str, email: str, password: str, prefixes: Dict[str,str] = None):
"""
Constructor requiring the server address, the user and password of KNORA
:param server: Adress of the server, e.g http://data.dasch.swiss
:param user: Username for Knora e.g., root@example.com
:param password: The password, e.g. test
:param server: Address of the server, e.g http://data.dasch.swiss
:param email: Email of user, e.g., root@example.com
:param password: Password of the user, e.g. test
"""
self.server = server
self.prefixes = prefixes
@@ -105,23 +105,27 @@ def __init__(self, server: str, email: str, password: str, prefixes: Dict[str,st
}
jsondata = json.dumps(credentials)

req = requests.post(self.server + '/v2/authentication',
headers={'Content-Type': 'application/json; charset=UTF-8'},
data=jsondata)
req = requests.post(
self.server + '/v2/authentication',
headers={'Content-Type': 'application/json; charset=UTF-8'},
data=jsondata
)

self.on_api_error(req)

result = req.json()
self.token = result["token"]

def __del__(self):
req = requests.delete(self.server + '/v2/authentication',
headers={'Authorization': 'Bearer ' + self.token})
result = req.json()
req = requests.delete(
self.server + '/v2/authentication',
headers={'Authorization': 'Bearer ' + self.token}
)

result = req.json()
pprint.pprint(result)



def on_api_error(self, res):
"""
Method to check for any API errors

0 comments on commit 2460937

Please sign in to comment.