lippertzpy 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lippertzpy-0.1.0/PKG-INFO +12 -0
- lippertzpy-0.1.0/README.md +3 -0
- lippertzpy-0.1.0/lippertzpy/__init__.py +14 -0
- lippertzpy-0.1.0/lippertzpy/api.py +73 -0
- lippertzpy-0.1.0/lippertzpy/logging.py +54 -0
- lippertzpy-0.1.0/lippertzpy.egg-info/PKG-INFO +12 -0
- lippertzpy-0.1.0/lippertzpy.egg-info/SOURCES.txt +10 -0
- lippertzpy-0.1.0/lippertzpy.egg-info/dependency_links.txt +1 -0
- lippertzpy-0.1.0/lippertzpy.egg-info/requires.txt +2 -0
- lippertzpy-0.1.0/lippertzpy.egg-info/top_level.txt +1 -0
- lippertzpy-0.1.0/pyproject.toml +18 -0
- lippertzpy-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lippertzpy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python helpers for the Jifeline partner API and logging
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: python-dotenv>=1.0
|
|
8
|
+
Requires-Dist: requests>=2.31
|
|
9
|
+
|
|
10
|
+
[README Deutsch](readme/README-de.md)
|
|
11
|
+
|
|
12
|
+
[README English](readme/README-en.md)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Client library for the Jifeline partner API."""
|
|
2
|
+
|
|
3
|
+
from .api import delete, get, get_access_token, post, put
|
|
4
|
+
from .logging import setup_logging, write_log
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"delete",
|
|
8
|
+
"get",
|
|
9
|
+
"get_access_token",
|
|
10
|
+
"post",
|
|
11
|
+
"put",
|
|
12
|
+
"setup_logging",
|
|
13
|
+
"write_log",
|
|
14
|
+
]
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Helpers for calling the Jifeline partner API."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
import requests
|
|
8
|
+
from dotenv import load_dotenv
|
|
9
|
+
|
|
10
|
+
API_URL = "https://partner-api-001.prd.jifeline.cloud/v2/"
|
|
11
|
+
TOKEN_URL = "https://jifeline-user-pool-prd.auth.eu-central-1.amazoncognito.com/oauth2/token"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _load_environment() -> None:
|
|
15
|
+
"""Load .env from the directory containing the main script."""
|
|
16
|
+
script_path = Path(sys.argv[0]).resolve()
|
|
17
|
+
env_path = script_path.parent / ".env"
|
|
18
|
+
load_dotenv(env_path, override=False)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_access_token() -> str:
|
|
22
|
+
"""Request an OAuth access token using client credentials."""
|
|
23
|
+
_load_environment()
|
|
24
|
+
client_id = os.getenv("client_id")
|
|
25
|
+
client_secret = os.getenv("client_secret")
|
|
26
|
+
if not client_id or not client_secret:
|
|
27
|
+
raise RuntimeError("client_id oder client_secret fehlt in der .env-Datei.")
|
|
28
|
+
|
|
29
|
+
response = requests.post(
|
|
30
|
+
TOKEN_URL,
|
|
31
|
+
data={
|
|
32
|
+
"grant_type": "client_credentials",
|
|
33
|
+
"client_id": client_id,
|
|
34
|
+
"client_secret": client_secret,
|
|
35
|
+
},
|
|
36
|
+
headers={"Content-Type": "application/x-www-form-urlencoded"},
|
|
37
|
+
timeout=30,
|
|
38
|
+
)
|
|
39
|
+
response.raise_for_status()
|
|
40
|
+
return response.json()["access_token"]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _headers() -> dict[str, str]:
|
|
44
|
+
return {
|
|
45
|
+
"Authorization": f"Bearer {get_access_token()}",
|
|
46
|
+
"Content-Type": "application/json",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def post(endpoint: str, data: object) -> dict:
|
|
51
|
+
response = requests.post(f"{API_URL}{endpoint}", json=data, headers=_headers(), timeout=30)
|
|
52
|
+
response.raise_for_status()
|
|
53
|
+
return response.json()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def get(endpoint: str) -> dict:
|
|
57
|
+
response = requests.get(f"{API_URL}{endpoint}", headers=_headers(), timeout=30)
|
|
58
|
+
response.raise_for_status()
|
|
59
|
+
return response.json()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def put(endpoint: str, data: object) -> dict:
|
|
63
|
+
response = requests.put(f"{API_URL}{endpoint}", json=data, headers=_headers(), timeout=30)
|
|
64
|
+
response.raise_for_status()
|
|
65
|
+
return response.json()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def delete(endpoint: str) -> dict:
|
|
69
|
+
response = requests.delete(f"{API_URL}{endpoint}", headers=_headers(), timeout=30)
|
|
70
|
+
response.raise_for_status()
|
|
71
|
+
if not response.content:
|
|
72
|
+
return {}
|
|
73
|
+
return response.json()
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Logging helpers used by the library."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def setup_logging(log_name: str | None = None) -> str | None:
|
|
11
|
+
"""Configure console and file logging and return the log file path."""
|
|
12
|
+
if os.environ.get("CHECK_SEPA_COMBINED_LOG") == "1":
|
|
13
|
+
return None
|
|
14
|
+
|
|
15
|
+
script_dir = Path(sys.argv[0]).resolve().parent
|
|
16
|
+
log_dir = script_dir / "log"
|
|
17
|
+
log_dir.mkdir(exist_ok=True)
|
|
18
|
+
script_name = log_name or Path(sys.argv[0]).stem or "lippertzpy"
|
|
19
|
+
safe_name = "".join(
|
|
20
|
+
character if character.isalnum() or character in "-_" else "_"
|
|
21
|
+
for character in script_name
|
|
22
|
+
)
|
|
23
|
+
log_file = log_dir / f"{safe_name}-{datetime.now():%Y-%m-%d_%H-%M}.log"
|
|
24
|
+
|
|
25
|
+
logging.basicConfig(
|
|
26
|
+
level=logging.INFO,
|
|
27
|
+
format="[%(asctime)s] [%(levelname)s] %(message)s",
|
|
28
|
+
handlers=[
|
|
29
|
+
logging.FileHandler(log_file, encoding="utf-8"),
|
|
30
|
+
logging.StreamHandler(),
|
|
31
|
+
],
|
|
32
|
+
)
|
|
33
|
+
return str(log_file)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
_log_file = setup_logging()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def write_log(message: str, level: str = "INFO", retries: int = 6, delay_ms: int = 150) -> None:
|
|
40
|
+
"""Write a message to the configured log and console."""
|
|
41
|
+
del retries, delay_ms
|
|
42
|
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
43
|
+
log_entry = f"[{timestamp}] [{level}] {message}"
|
|
44
|
+
if _log_file is not None:
|
|
45
|
+
logging.log(getattr(logging, level.upper(), logging.INFO), message)
|
|
46
|
+
|
|
47
|
+
if os.environ.get("CHECK_SEPA_COMBINED_LOG") == "1":
|
|
48
|
+
script_name = os.environ.get("CHECK_SEPA_SCRIPT_NAME") or Path(sys.argv[0]).stem
|
|
49
|
+
print(f"[{script_name}] {log_entry}", flush=True)
|
|
50
|
+
return
|
|
51
|
+
|
|
52
|
+
color = {"ERROR": "91", "WARNING": "93", "SUCCESS": "92", "RUN": "94"}.get(level.upper())
|
|
53
|
+
output = f"[{timestamp}] {message}"
|
|
54
|
+
print(f"\033[{color}m{output}\033[0m" if color else output)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lippertzpy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python helpers for the Jifeline partner API and logging
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: python-dotenv>=1.0
|
|
8
|
+
Requires-Dist: requests>=2.31
|
|
9
|
+
|
|
10
|
+
[README Deutsch](readme/README-de.md)
|
|
11
|
+
|
|
12
|
+
[README English](readme/README-en.md)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
lippertzpy/__init__.py
|
|
4
|
+
lippertzpy/api.py
|
|
5
|
+
lippertzpy/logging.py
|
|
6
|
+
lippertzpy.egg-info/PKG-INFO
|
|
7
|
+
lippertzpy.egg-info/SOURCES.txt
|
|
8
|
+
lippertzpy.egg-info/dependency_links.txt
|
|
9
|
+
lippertzpy.egg-info/requires.txt
|
|
10
|
+
lippertzpy.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lippertzpy
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "lippertzpy"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python helpers for the Jifeline partner API and logging"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"python-dotenv>=1.0",
|
|
13
|
+
"requests>=2.31",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[tool.setuptools.packages.find]
|
|
17
|
+
where = ["."]
|
|
18
|
+
include = ["lippertzpy*"]
|