From 47ca27291fa2cd20df8634e8778f75a41a0b3b6a Mon Sep 17 00:00:00 2001 From: MaPaLo76 <@MaPaLo76> Date: Tue, 17 Sep 2024 19:00:46 +0200 Subject: [PATCH] moved secrets into environment vars. The .env file is used in docker-compose. reportMissingThekendienst.py evaluate these with os.getenv(). --- build-docker-container.sh | 2 ++ cfg/base_config.json | 23 +++++++++++++++++++++++ docker/docker-compose.yaml | 2 ++ docker/template.env | 3 +++ src/reportMissingThekendienst.py | 7 ++++--- 5 files changed, 34 insertions(+), 3 deletions(-) create mode 100755 build-docker-container.sh create mode 100644 cfg/base_config.json create mode 100644 docker/template.env diff --git a/build-docker-container.sh b/build-docker-container.sh new file mode 100755 index 0000000..3f045f4 --- /dev/null +++ b/build-docker-container.sh @@ -0,0 +1,2 @@ +# docker build -t gitea.majufilo.eu/matthias.lotz/thekendienstbot:latest -f ./docker/Dockerfile . +docker build -t thekendienstbot:latest -f ./docker/Dockerfile . diff --git a/cfg/base_config.json b/cfg/base_config.json new file mode 100644 index 0000000..53408bc --- /dev/null +++ b/cfg/base_config.json @@ -0,0 +1,23 @@ +{ + "calendar_id": "ksp4hsa93c1nt5kmym", + "telegram_channels": [{"name": "Thekenhelden", "id": -1001302667129}, {"name": "Team Chat", "id": -1001361066996> + "subcalendars_to_check": ["flexibler Thekendienst", "regelmäßiger Thekendienst"], + "default_subcalendar_for_new_event": ["flexibler Thekendienst"], + "timezone": "Europe/Berlin", + "header": "Es gibt noch offene Thekendienste für diese Woche\\!\nWer kann bitte im [Kalender](https://teamup.com> + "footer": "\\- Der freundliche Theckendiensterinnerungsbot", + "no_open_slots": "Juhu\\! Diese Woche gibt es keine offenen [Slots](https://teamup.com/ksp4hsa93c1nt5kmym)\\!", + "appointment_motivator": "Da mache ich Theke\\.", + "start_date": "tomorrow", + "time_slots": { + "Monday": {"start": "17:00", "end": "22:00"}, + "Tuesday": {"start": "17:00", "end": "22:00"}, + "Wednesday": {"start": "17:00", "end": "22:00"}, + "Thursday": {"start": "17:00", "end": "22:00"}, + "Friday": {"start": "15:00", "end": "22:00"}, + "Saturday": {"start": "12:00", "end": "22:00"}, + "Sunday": {"start": "12:00", "end": "20:00"} + } +} + + diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 33dfb1c..2c55d7d 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -9,6 +9,8 @@ services: container_name: thekendienstbot environment: - TZ=Europe/Berlin + env_file: + - .env volumes: - /home/hobbyadmin/ThekendienstBot/cfg/:/app/cfg/ - /home/hobbyadmin/ThekendienstBot/src/:/app/src/ diff --git a/docker/template.env b/docker/template.env new file mode 100644 index 0000000..cf41cc4 --- /dev/null +++ b/docker/template.env @@ -0,0 +1,3 @@ +# copy this file to .env and fill in the values +TEAMUP_API_KEY=enter your teamup api key here +TELEGRAM_BOT_TOKEN=enter your telegram bot token here diff --git a/src/reportMissingThekendienst.py b/src/reportMissingThekendienst.py index 6a5cde6..71494f4 100644 --- a/src/reportMissingThekendienst.py +++ b/src/reportMissingThekendienst.py @@ -1,4 +1,5 @@ from typing import List, Tuple +import os import urllib.parse import requests import json @@ -149,7 +150,7 @@ async def send_telegram_message(bot_token, channels, message): def fetch_subcalendar_id_from_name(config) -> List[Subcalendar]: subcalendar_ids = fetch_subcalendar_ids( - config["teamup_api_key"], config["calendar_id"] + os.getenv("TEAMUP_API_KEY"), config["calendar_id"] ) interesting_calendars = config["subcalendars_to_check"] subcalendars_to_check = [ @@ -272,7 +273,7 @@ async def check_slots_and_notify(config: map, dry_run: bool = False) -> None: ) events = fetch_events( - config["teamup_api_key"], + os.getenv("TEAMUP_API_KEY"), config["calendar_id"], start_date, end_date, @@ -296,7 +297,7 @@ async def check_slots_and_notify(config: map, dry_run: bool = False) -> None: else: if had_message_without_footer: await send_telegram_message( - config["telegram_bot_token"], config["telegram_channels"], message + os.getenv("TELEGRAM_BOT_TOKEN"), config["telegram_channels"], message ) if __name__ == "__main__": -- 2.45.1