From 2fec02b2193265801a1116ebbb57c4642516edf9 Mon Sep 17 00:00:00 2001 From: Dominik Strangas Date: Thu, 5 Sep 2024 10:10:08 +0200 Subject: [PATCH] fix: files not copied feat: adjusted example data fix: missing libs in req.txt --- .env copy | 6 +++--- Dockerfile | 2 +- docker-compose.yml | 6 ++++-- main.py | 6 +++++- requirements.txt | 1 + services.json | 7 ++----- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.env copy b/.env copy index 2ce5cdb..15d5494 100644 --- a/.env copy +++ b/.env copy @@ -1,5 +1,5 @@ -MAIL_SERVER=mail.mailone24.de -MAIL_USER=management@oceanwave018.de +MAIL_SERVER=mail.server.de +MAIL_USER=your@mail.de MAIL_PASSWORD= MAIL_PORT=587 -EMAIL_RECEIVER=sr.strangas@gmail.com \ No newline at end of file +EMAIL_RECEIVER=reciever@mail.de \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 691819d..b5a26d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ RUN pip install --no-cache-dir -r requirements.txt RUN apt-get update && apt-get install -y cron # Add the cron job to run the Python script weekly (every Sunday at 3 AM) -RUN echo "*/5 * * * * /usr/local/bin/python3 /usr/src/app/main.py >> /var/log/cron.log 2>&1" > /etc/cron.d/weekly_job +RUN echo "0 11 * * 0 /usr/local/bin/python3 /usr/src/app/main.py >> /var/log/cron.log 2>&1" > /etc/cron.d/weekly_job # Give execution rights on the cron job RUN chmod 0644 /etc/cron.d/weekly_job diff --git a/docker-compose.yml b/docker-compose.yml index cf0ab47..14b6783 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,11 +2,13 @@ version: '3.8' services: python-cron-job: - build: . + build: + context: . + dockerfile: ./Dockerfile container_name: python-cron-job restart: unless-stopped volumes: - - ./app:/usr/src/app # Mount your local app directory to the container + - ./services.json:/usr/src/app/services.json # Mount your local app directory to the container environment: - TZ=UTC # Set the timezone (you can adjust this as needed) logging: diff --git a/main.py b/main.py index c48171e..e29d625 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import json import requests import os import smtplib +import pathlib from dotenv import load_dotenv from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText @@ -129,6 +130,7 @@ def send_email(status_dict, server, user, password, receiver): try: with smtplib.SMTP(server, port=os.getenv("MAIL_PORT")) as smtp: + smtp.connect(server, os.getenv("MAIL_PORT")) smtp.starttls() smtp.login(user, password) smtp.sendmail(user, receiver, message.as_string()) @@ -148,7 +150,9 @@ def main(): receiver = os.getenv("EMAIL_RECEIVER") # Load services and check their status - services = load_services("./services.json") + cwd = pathlib.Path(__file__).parent.resolve() + print("%s/services.json"%cwd) + services = load_services("%s/services.json"%cwd) status_dict = {url: check_service_status(url) for url in services} print(status_dict) diff --git a/requirements.txt b/requirements.txt index 0c9909e..d51c573 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ certifi==2024.8.30 charset-normalizer==3.3.2 idna==3.8 +pathlib==1.0.1 python-dotenv==1.0.1 requests==2.32.3 urllib3==2.2.2 diff --git a/services.json b/services.json index 68cb929..5f71f49 100644 --- a/services.json +++ b/services.json @@ -1,7 +1,4 @@ [ - "https://brunnergarten-muc.de/", - "https://cms.brunnergarten-muc.de/", - "https://nextcloud.oceanwave018.de/", - "https://hilfe.oceanwave018.de/", - "https://traefik.oceanwave018.de/" + "https://another.your-domain.de", + "https://your-domain.de" ] \ No newline at end of file