Skip to content

Commit

Permalink
fix: add folder independence
Browse files Browse the repository at this point in the history
  • Loading branch information
subotic committed Mar 22, 2019
1 parent 7f79530 commit 2460937
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
7 changes: 5 additions & 2 deletions knora/create_ontology.py
@@ -1,3 +1,4 @@
import os
from typing import List, Set, Dict, Tuple, Optional
from pprint import pprint
import argparse
Expand All @@ -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
Expand Down
24 changes: 14 additions & 10 deletions knora/knora.py
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2460937

Please sign in to comment.