thsf.net/src/thsf/backend/__init__.py

16 lines
465 B
Python
Raw Normal View History

2023-04-08 05:17:49 +02:00
import requests
2023-04-08 21:17:34 +02:00
import logging
2023-04-08 05:17:49 +02:00
2023-04-08 21:17:34 +02:00
class Backend:
2023-04-08 05:17:49 +02:00
def __init__(self, url, apiprefix, apikey):
self.url = url
self.apiprefix = apiprefix
self.apikey = apikey
self.session = requests.Session()
def get(self, endpoint, params=None):
url = f"{self.url}/{self.apiprefix}/{endpoint}"
2023-04-08 21:17:34 +02:00
headers = {"Authorization": f"Token {self.apikey}",
"Accept": "application/json"}
return self.session.get(url, params=params, headers=headers)