first docker release
This commit is contained in:
parent
c327998c10
commit
ae13431522
14
docker/Dockerfile
Normal file
14
docker/Dockerfile
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
FROM python:3.8-slim
|
||||||
|
|
||||||
|
# Arbeitsverzeichnis im Container festlegen
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Abhängigkeiten installieren
|
||||||
|
COPY requirements.txt ./
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# Skript in das Arbeitsverzeichnis kopieren
|
||||||
|
COPY nox-forum-watcher.v1.py .
|
||||||
|
|
||||||
|
# Script festlegen, der ausgeführt werden soll, wenn der Container startet
|
||||||
|
CMD [ "python", "./nox-forum-watcher.v1.py" ]
|
14
docker/docker-compose.yaml
Normal file
14
docker/docker-compose.yaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
nox-forum-watcher:
|
||||||
|
build: .
|
||||||
|
container_name: nox-forum-watcher
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
SMTP_SERVER: smtp.media-techport.int
|
||||||
|
SMTP_PORT: 25
|
||||||
|
SENDER_EMAIL: noreply@media-techport.de
|
||||||
|
RECEIVER_EMAIL:
|
||||||
|
FORUM_URL: https://forum.nox.to/index.php?thread/133929-gutschein-angebote/
|
||||||
|
FORUM_TOPIC: Forum NOX.TO | Gutschein Angebote
|
48
docker/nox-forum-watcher.v1.py
Normal file
48
docker/nox-forum-watcher.v1.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import os
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import smtplib
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Umgebungsvariablen
|
||||||
|
smtp_server = os.getenv('SMTP_SERVER', 'default-smtp-server')
|
||||||
|
smtp_port = int(os.getenv('SMTP_PORT', 25))
|
||||||
|
absender_email = os.getenv('SENDER_EMAIL', 'default-sender@example.com')
|
||||||
|
empfaenger_email = os.getenv('RECEIVER_EMAIL', 'default-receiver@example.com')
|
||||||
|
url = os.getenv('FORUM_URL', 'default-forum-url')
|
||||||
|
topic = os.getenv('FORUM_TOPIC', 'default-forum-topic')
|
||||||
|
wait_time = int(os.getenv('WAIT_TIME', 60))
|
||||||
|
|
||||||
|
# Letzter bekannter Beitrag
|
||||||
|
letzter_beitrag = ""
|
||||||
|
|
||||||
|
while True:
|
||||||
|
response = requests.get(url)
|
||||||
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
|
|
||||||
|
# Alle Beiträge gemäß des festgelegten Musters auswählen
|
||||||
|
beitraege = soup.select('div:nth-child(3) > header:nth-child(1) > ul:nth-child(2) > li:nth-child(1) > a:nth-child(1)')
|
||||||
|
|
||||||
|
# Überprüfe, ob neue Beiträge vorhanden sind
|
||||||
|
if beitraege and beitraege[-1].text != letzter_beitrag:
|
||||||
|
neuer_beitrag = beitraege[-1].text
|
||||||
|
letzter_beitrag = neuer_beitrag
|
||||||
|
|
||||||
|
# E-Mail-Inhalte
|
||||||
|
subject = "Neuer Beitrag im Forum"
|
||||||
|
body = f"Es gibt einen neuen Forenbeitrag im Thema: {topic}\n\nLink zum Beitrag: {url}"
|
||||||
|
|
||||||
|
# E-Mail senden
|
||||||
|
msg = MIMEText(body)
|
||||||
|
msg['Subject'] = subject
|
||||||
|
msg['From'] = absender_email
|
||||||
|
msg['To'] = empfaenger_email
|
||||||
|
|
||||||
|
# Verbindung zum SMTP-Server herstellen
|
||||||
|
server = smtplib.SMTP(smtp_server, smtp_port)
|
||||||
|
server.send_message(msg)
|
||||||
|
server.quit()
|
||||||
|
|
||||||
|
# Wartezeit zwischen den Überprüfungen
|
||||||
|
time.sleep(wait_time)
|
2
docker/requirements.txt
Normal file
2
docker/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
requests
|
||||||
|
beautifulsoup4
|
Loading…
Reference in New Issue
Block a user