So I have written a script to summarize a few newsletters and send them to me in Telegram. The script itself works perfectly. Now I tried to run this script every morning at 7 via crontab on a Ubunutu Server. The Log File looks fine, every print() I used in the script shows up normally without errors, but the it doesn’t send the message.
My Crontab command:
00 12 * * * DISPLAY=:0 /usr/bin/python3 /root/data/App/Briefing/main.py >> /home/main.log &2>1
Python scripts:
main.py
import ai as AiHandler
import mail as MailHandler
import send as Telegram
import pandas as pd
from datetime import date
def start():
files = MailHandler.scanEmails()
files = AiHandler.summarize(files)
print(files)
data = pd.read_csv('checkpoint.csv', sep=';')
checkpoint = createMsg(data)
s = f"morgentliches Briefing vom {date.today().strftime("%d.%m.%Y")}".replace(".", "\.")
s += "nnn ☕️ *Die* *Lage* *am* *Morgen* *\-* *Spiegel*nnn" + createMsg(pd.read_csv('spiegel.csv', sep=';'))
s += "nnn ???? *Berlin* *\-* *Tagesspiegel* *Checkpoint*nnn" + checkpoint
s += "nnn???? *Tech* *Update* *\-* *ManagerMagazin* nnn" + createMsg(pd.read_csv('manager.csv', sep=';'))
Telegram.sendMessage(s)
def createMsg(data):
s = ""
for i in range(5):
thema = data['Thema'][i].replace('*', '\*')
zsm = data['Zusammenfassung'][i].replace('*', '\*')
s += "????t" + "*" + thema + "*" + "n"
s += zsm + "n"
s = s.replace("-", "\-")
s = s.replace(".", "\.")
s = s.replace("(", "\(")
s = s.replace(")", "\)")
#s = s.replace("*", "\*")
s = s.replace("!", "\!")
return s
start()
send.py
import telebot
def sendMessage(msg):
bot = telebot.TeleBot("7227173154:AAG_mXCBqa_lBsOYQ9uqz52GhRQu90AoDJA")
bot.send_message(chat_id="@morgenbriefing", text=msg, parse_mode="MarkdownV2")
I tried adding DISPLAY:=0 to the crontab command but it didnt help