diff options
Diffstat (limited to 'python/markit_parse.py')
| -rw-r--r-- | python/markit_parse.py | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/python/markit_parse.py b/python/markit_parse.py index 5b6a36a9..5f49f411 100644 --- a/python/markit_parse.py +++ b/python/markit_parse.py @@ -2,23 +2,22 @@ from serenitas.utils.misc import get_credential_path import json import posixpath from urllib.parse import urljoin -from typing import ClassVar import requests -class MarkitAPI: - api_key: ClassVar = None - base_url: ClassVar = None +def load_api_key(): + with get_credential_path("markit_api").open() as fh: + creds = json.load(fh) + base_url = creds.pop("url") + r = requests.post( + urljoin(base_url, "apikey"), + data=creds, + ) + return base_url, r.text - @classmethod - def set_api(cls): - creds = cls.get_creds() - r = requests.post( - urljoin(creds["url"], "apikey"), - data={"username": creds["username"], "password": creds["password"]}, - ) - cls.api_key = r.text - cls.base_url = creds["url"] + +class MarkitAPI: + base_url, api_key = load_api_key() @classmethod def get_data(cls, asset_class, service="latest"): @@ -35,9 +34,3 @@ class MarkitAPI: r = requests.get(url, params) # print(r.status_code, r.text[:100]) return json.loads(r.text) - - @classmethod - def get_creds(cls): - cred_path = get_credential_path("markit_api") - creds = json.load(cred_path.open()) - return creds |
