From 55d45176d22cff6d9a06f3cc7f45c750103cc137 Mon Sep 17 00:00:00 2001
From: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
Date: Wed, 9 Sep 2020 19:13:53 +0200
Subject: [PATCH] fix some errors

---
 Dockerfile          | 16 ++++++++--------
 crontab             |  2 +-
 run.sh              | 17 ++++++++++-------
 src/program_info.py |  2 +-
 src/telegram_bot.py |  4 ++--
 src/twitter_bot.py  |  4 ++--
 6 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 89fc3888..8dff8272 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 85af2c8e..7a13302a 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 0c5c4369..695c4cee 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 ef51dcaa..25635fbb 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 e133093e..8d77c25a 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 37a59f07..bdcd18a7 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
 ]
 
-- 
GitLab