init commit
This commit is contained in:
88
python/FET_Infoscreen_bot.py
Executable file
88
python/FET_Infoscreen_bot.py
Executable file
@@ -0,0 +1,88 @@
|
||||
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)
|
||||
49
python/FET_photoDownload.py
Normal file
49
python/FET_photoDownload.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from os import path
|
||||
import shutil
|
||||
from random import randint
|
||||
|
||||
#
|
||||
# This script was written by pet@fet.at in 1.2021
|
||||
# It is used by the FET_infoscreen bot
|
||||
# It gets an image, saves it in a folder and moves the oldest image into a different one
|
||||
# 10 Images is preconfigured
|
||||
#
|
||||
|
||||
|
||||
def photoDownload(photo, username, userid):
|
||||
|
||||
#save file after checking if we've got a collision
|
||||
filepath = "../slideshow/"+username+"-"+userid+"-"+str(randint(10, 1000))+".jpg" #first try with lower numbers
|
||||
while path.exists("filepath"):
|
||||
filepath = "../slideshow/"+username+"-"+userid+"-"+str(randint(1000, 99999999))+".jpg"
|
||||
photo.download(filepath)
|
||||
|
||||
recent_images_file = open("recent_images.txt", "r")
|
||||
recent_images = recent_images_file.readlines()
|
||||
recent_images.append(filepath) # add the newest photo
|
||||
recent_images_file.close()
|
||||
print(recent_images)
|
||||
|
||||
if len(recent_images) >= 10:
|
||||
first_image = 0
|
||||
else:
|
||||
first_image = 1
|
||||
|
||||
recent_images_file = open("recent_images.txt", "w")
|
||||
|
||||
for image in recent_images:
|
||||
#print("Image: "+str(image.strip()))
|
||||
if first_image == 0:
|
||||
#print(str(image.strip() + " moved to old.")
|
||||
image_name= image.split("slideshow/",1)[1] # get the image name without path
|
||||
try: #try to move it if it has not been deleted
|
||||
shutil.move(image.rstrip(), "../slideshow/old/"+image_name)
|
||||
except:
|
||||
pass
|
||||
first_image = 1
|
||||
else:
|
||||
#print(image.strip() + " saved.")
|
||||
recent_images_file.write(image.rstrip() + "\n")
|
||||
|
||||
|
||||
recent_images_file.close()
|
||||
BIN
python/__pycache__/FET_photoDownload.cpython-37.pyc
Normal file
BIN
python/__pycache__/FET_photoDownload.cpython-37.pyc
Normal file
Binary file not shown.
0
python/index.php
Executable file
0
python/index.php
Executable file
1596445
python/infoscreen_bot.log
Normal file
1596445
python/infoscreen_bot.log
Normal file
File diff suppressed because it is too large
Load Diff
1
python/last_update_id.txt
Normal file
1
python/last_update_id.txt
Normal file
@@ -0,0 +1 @@
|
||||
174751632
|
||||
9
python/recent_images.txt
Executable file
9
python/recent_images.txt
Executable file
@@ -0,0 +1,9 @@
|
||||
../slideshow/bogdylan-837638978-517.jpg
|
||||
../slideshow/bogdylan-837638978-108.jpg
|
||||
../slideshow/bogdylan-837638978-971.jpg
|
||||
../slideshow/TimothyTheKing-1113014551-593.jpg
|
||||
../slideshow/edgelord1-1611286282-935.jpg
|
||||
../slideshow/edgelord1-1611286282-48.jpg
|
||||
../slideshow/edgelord1-1611286282-465.jpg
|
||||
../slideshow/Leuti-832042206-457.jpg
|
||||
../slideshow/edgelord1-1611286282-531.jpg
|
||||
5
python/start_FET_Infoscreen_bot.sh
Executable file
5
python/start_FET_Infoscreen_bot.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
cd /var/www/infoscreen/python
|
||||
python3 -u FET_Infoscreen_bot.py > /var/www/infoscreen/python/infoscreen_bot.log 2>&1 &
|
||||
|
||||
3854
python/ystemctl status mariadb.service
Normal file
3854
python/ystemctl status mariadb.service
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user