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 AiHandlerimport mail as MailHandlerimport send as Telegramimport pandas as pdfrom datetime import datedef 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 += "\n\n\n ☕️ *Die* *Lage* *am* *Morgen* *\\-* *Spiegel*\n\n\n" + createMsg(pd.read_csv('spiegel.csv', sep=';')) s += "\n\n\n 🐻 *Berlin* *\\-* *Tagesspiegel* *Checkpoint*\n\n\n" + checkpoint s += "\n\n\n🔌 *Tech* *Update* *\\-* *ManagerMagazin* \n\n\n" + 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 sstart()
send.py
import telebotdef sendMessage(msg): bot = telebot.TeleBot("XXXXXX") bot.send_message(chat_id="@morgenbriefing", text=msg, parse_mode="MarkdownV2")
I tried adding DISPLAY:=0 to the crontab command but it didnt help