Working config loading from TOML, env var, cli args
This commit is contained in:
@ -1,7 +1,5 @@
|
||||
from datetime import datetime
|
||||
import requests
|
||||
import requests_cache
|
||||
import os
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
@ -11,14 +9,12 @@ class NotFound(Exception):
|
||||
|
||||
|
||||
class KimaiAPI(object):
|
||||
# temporary hardcoded config
|
||||
KIMAI_API_URL = "https://kimai.autonomic.zone/api"
|
||||
# KIMAI_API_URL = "https://kimaitest.autonomic.zone/api"
|
||||
|
||||
def __init__(self, username=None, api_key=None):
|
||||
def __init__(self, username=None, api_key=None, api_url=None):
|
||||
self.auth_headers = {"X-AUTH-USER": username, "X-AUTH-TOKEN": api_key}
|
||||
self.kimai_api_url = api_url
|
||||
# NOTE: Uncomment the following line to enable requests_cache, which can make development a *lot* faster
|
||||
# TODO: Add a config option or something for this
|
||||
# import requests_cache
|
||||
# requests_cache.install_cache("kimai", backend="sqlite", expire_after=1800)
|
||||
self.customers_json = self.get("customers", {"visible": 3})
|
||||
self.projects_json = self.get("projects", {"visible": 3, "ignoreDates": 1})
|
||||
@ -27,7 +23,7 @@ class KimaiAPI(object):
|
||||
|
||||
def get(self, endpoint, params=None):
|
||||
result = requests.get(
|
||||
f"{self.KIMAI_API_URL}/{endpoint}", params=params, headers=self.auth_headers
|
||||
f"{self.kimai_api_url}/{endpoint}", params=params, headers=self.auth_headers
|
||||
).json()
|
||||
try:
|
||||
if result["code"] != 200:
|
||||
@ -38,7 +34,7 @@ class KimaiAPI(object):
|
||||
|
||||
def post(self, endpoint, data):
|
||||
return requests.post(
|
||||
f"{self.KIMAI_API_URL}/{endpoint}", json=data, headers=self.auth_headers
|
||||
f"{self.kimai_api_url}/{endpoint}", json=data, headers=self.auth_headers
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user