from telegram.ext import Updater, CommandHandler import telegram import FET_photoDownload import time import sys from datetime import datetime # # This script was written by pet@fet.at in 1.2021 # It is used to get images sent to a telegram bot and save them to a folder # It will automatically keep the last 10 and move the older ones to a different folder # #sys.stdout = open('infoscreen_bot.log', 'a') print("Started") def FET_infoscreen_bot(): while True: bot = telegram.Bot(token='1687598897:AAGt9XsK5oGF9Eoz8hRq96q7rkRfHn8mBJ4') #print(bot.get_me()) #check the id of the last message we've read to start from there last_update_id_file = open("last_update_id.txt", "r") last_update_id = int(last_update_id_file.read()) last_update_id_file.close() updates = bot.get_updates(last_update_id+1) for u in updates: now = datetime.now() current_time = now.strftime("%Y%m%d-%H:%M:%S") print(str(current_time) + " Received Messages:") #print(u) chat_id = u.message.chat_id username = str(u.message.from_user['username']) userid = str(u.message.from_user['id']) print("From:" + str(username)) print("Id:" + str(u.update_id)) print("Text:" + str(u.message.text)) if u.message.text == "/start": answer = """Wie benütze ich den FET-Infoscreen und was ist das eigentlich: *Der Infoscreen hängt vor der Bürotür der FET (siehe fet.at) *Er zeigt automatisch die letzten 10 an diesen Channel gesendeten Fotos in einer Slideshow an. *Das schaut so aus: infoscreen.fet.at *Bitte melde unpassende Inhalte direkt an service@fet.at""" bot.send_message(chat_id=chat_id, text=answer) elif u.message.text == "/help": answer = """Wie benütze ich den FET-Infoscreen und was ist das eigentlich: *Der Infoscreen hängt vor der Bürotür der FET (siehe fet.at) *Er zeigt automatisch die letzten 10 an diesen Channel gesendeten Fotos in einer Slideshow an. *Das schaut so aus: infoscreen.fet.at *Bitte melde unpassende Inhalte direkt an service@fet.at""" bot.send_message(chat_id=chat_id, text=answer) elif u.message.photo: print("Photo gefunden.") answer = "Danke "+username+""", sehr fein dieses Foto. Ich werds gleich auf den Infoscreen legen und mit den letzten 9 anderen Fotos durchrotieren. *Das dauert immer etwas, da der Infoscreen sehr langsam rotiert, gib mir 5min. *Bitte melde unpassende Inhalte direkt an service@fet.at""" bot.send_message(chat_id=chat_id, text=answer) photo = bot.getFile(u.message.photo[-1].file_id) FET_photoDownload.photoDownload(photo, username, userid) else: answer = """Des check i ned. Ich kann nicht lesen.. *Schick mir entweder /help für Hilfe oder direkt ein Bild das du am Infoscreen sehen willst. *Frag alternativ @ppetl für weitere Infos. *Bitte melde unpassende Inhalte direkt an service@fet.at""" bot.send_message(chat_id=chat_id, text=answer) last_update_id = u.update_id #save the id of the last message we've read so we don't have to start over last_update_id_file = open("last_update_id.txt", "w") last_update_id_file.write(str(last_update_id)) last_update_id_file.close() time.sleep(7) while True: try: FET_infoscreen_bot() except Exception as e: print("Exeption:") print(e)