Skip to content

Commit

Permalink
Merge pull request #186 from AndreWohnsland/dev
Browse files Browse the repository at this point in the history
Use new api in microservice
  • Loading branch information
AndreWohnsland authored Sep 9, 2024
2 parents 89a619c + 48cb491 commit c3b286f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
21 changes: 15 additions & 6 deletions microservice/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

DEFAULT_HOOK_EP = "enpointforhook"
DEFAULT_API_KEY = "readdocshowtoget"
API_ENDPOINT = "https://cocktailberryapi-1-u0613408.deta.app/cocktail"
OLD_API_ENDPOINT = "https://cocktailberryapi-1-u0613408.deta.app/cocktail"
API_ENDPOINT = "https://api.cocktailberry.org/api/v1/cocktail"


def generate_urls_and_headers() -> List[Tuple[str, Dict[str, str]]]:
Expand All @@ -13,9 +14,7 @@ def generate_urls_and_headers() -> List[Tuple[str, Dict[str, str]]]:
hook_headers_config = os.getenv("HOOK_HEADERS", None)
if hook_headers_config is None:
# If no headers are set, use common content type
hook_headers = {
"content-type": "application/json"
}
hook_headers = {"content-type": "application/json"}
else:
# Split the header config into a list
# the config is header:value,header2:value2
Expand All @@ -29,8 +28,18 @@ def generate_urls_and_headers() -> List[Tuple[str, Dict[str, str]]]:
use_api = (api_key != DEFAULT_API_KEY) and (api_key is not None)
endpoint_data = []
if use_hook:
endpoint_data.append((hook_url, hook_headers,))
endpoint_data.append(
(
hook_url,
hook_headers,
)
)
if use_api:
endpoint_data.append((API_ENDPOINT, api_headers,))
endpoint_data.append(
(
API_ENDPOINT,
api_headers,
)
)

return endpoint_data
5 changes: 5 additions & 0 deletions microservice/query_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from flask import Flask
from database import DatabaseHandler

from helper import API_ENDPOINT, OLD_API_ENDPOINT


def try_send_query_data(app: Flask):
db_handler = DatabaseHandler()
Expand All @@ -13,6 +15,9 @@ def try_send_query_data(app: Flask):
# Else try to send all remaining data
app.logger.info("Found some not sended data, trying to send ...")
for send_id, data, url, headers in failed_data:
# overwrite old endpoint
if url == OLD_API_ENDPOINT:
url = API_ENDPOINT
try:
res = requests.post(url, data=data, headers=json.loads(headers), timeout=10)
app.logger.info(f"Code: {res.status_code}, to: {url}, Payload: {data}")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "CocktailBerry"
version = "1.36.0"
version = "1.36.1"
description = "A Python and Qt based App for a Cocktail Machine on a Raspberry Pi. Easily serve Cocktails with Raspberry Pi and Python"
authors = [{ name= "Andre Wohnsland" , email = "[email protected]" }]
readme = "readme.md"
Expand Down
2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Literal

__version__ = "1.36.0"
__version__ = "1.36.1"
PROJECT_NAME = "CocktailBerry"
MAX_SUPPORTED_BOTTLES = 24
SupportedLanguagesType = Literal["en", "de"]
Expand Down

0 comments on commit c3b286f

Please sign in to comment.