diff --git a/Dockerfile b/Dockerfile index 89fc3888040b98f6230302ec3cd0b11346032561..8dff8272f07039d8e05d8171d3ccddd79e70bf9f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,19 @@ FROM python:3-alpine RUN apk upgrade --available --update +RUN apk add --no-cache msmtp tzdata -WORKDIR /usr/src/app -COPY requirements.txt ./ +RUN adduser --uid 1000 --disabled-password bot bot + +COPY requirements.txt /usr/src/app/requirements.txt RUN apk add --no-cache build-base && \ - pip install --no-cache-dir -r requirements.txt && \ + pip install --no-cache-dir -r /usr/src/app/requirements.txt && \ apk del build-base -COPY src . +COPY src /usr/src/app COPY run.sh /usr/local/bin/run.sh -COPY crontab /var/spool/cron/crontabs/programbot +COPY crontab /var/spool/cron/crontabs/bot RUN chmod +x /usr/local/bin/run.sh -RUN apk add --no-cache msmtp - -CMD ["crond", "-f"] +CMD ["crond", "-f", "-l", "0"] diff --git a/crontab b/crontab index 85af2c8e05702234941cb2e13f8a31dae2df9174..7a13302a8eeaf8c9ec37fc2831f452c59d791396 100644 --- a/crontab +++ b/crontab @@ -1 +1 @@ -* 9 * * * /usr/local/bin/run.sh >/dev/null 2>&1 +* * * * * /usr/local/bin/run.sh 2>&1 diff --git a/run.sh b/run.sh index 0c5c43692391185b6ac22c24b2b1dac6b525ca5a..695c4ceedeb348e01afe6ab08c12f0110d3a59d9 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh cd /usr/src/app @@ -19,11 +19,14 @@ function preview { echo "" } -OUTPUT="$(preview)" -if [ ! -z "$OUTPUT" ] -then +#if [ ! -z "$OUTPUT" ] +#then +(cat << EOF +Subject:Programm-Info-Bot +Content-Type: text/plain; charset=UTF-8 +$(preview)" +EOF +) | msmtp ${MSMTP_ARGUMENTS} -echo "$OUTPUT" | msmtp -a "Content-Type: text/plain; charset=UTF-8" ${MSMTP_ARGUMENTS} - -fi +#fi diff --git a/src/program_info.py b/src/program_info.py index ef51dcaa32d96ec9aac55325179f838fee7acd14..25635fbbb5611ff769955e131a3a28638cf80f39 100644 --- a/src/program_info.py +++ b/src/program_info.py @@ -85,7 +85,7 @@ class NextEvent: link = str(next_event["id"]) + "-" + link self.link = "https://ufc.tu-dortmund.de/vorstellung/%s" % link - if next_event["movie"]["youtube_id"] is not "": + if next_event["movie"]["youtube_id"] != "": self.trailer = "https://youtu.be/%s" % next_event["movie"]["youtube_id"] response = requests.get("https://ufc.tu-dortmund.de/%s" diff --git a/src/telegram_bot.py b/src/telegram_bot.py index e133093edb53617dab174db5fed9eb4e847f307b..8d77c25af970419181fb4624b707e6228475db1a 100755 --- a/src/telegram_bot.py +++ b/src/telegram_bot.py @@ -61,7 +61,7 @@ message = [ "\n", "*", next_event.title, "*\n", "\n", - next_event.description, "" if next_event.description is "" else "\n\n", + next_event.description, "" if next_event.description == "" else "\n\n", next_event.movie_description, "\n", "\n", next_event.tags, "\n", @@ -70,7 +70,7 @@ message = [ ] # Trailernachricht zusammenbauen -if next_event.trailer is not "": +if next_event.trailer != "": message.append("\n[Link zum Trailer](%s)" % next_event.trailer) text = ''.join(message) diff --git a/src/twitter_bot.py b/src/twitter_bot.py index 37a59f07e0d2376c5ddbedbb0a285ae86f71f966..bdcd18a723d18ba94e3937673b996a6e9bbfb622 100755 --- a/src/twitter_bot.py +++ b/src/twitter_bot.py @@ -67,9 +67,9 @@ message = [ "\n", next_event.title, "\n", - "" if next_event.description is "" else "\n", + "" if next_event.description == "" else "\n", next_event.description, - "" if next_event.description is "" else "\n\n", + "" if next_event.description == "" else "\n\n", "%s?pk_campaign=twitter" % next_event.link ]