I'm finally done with this Telegram bot

This commit is contained in:
Stefano Assenzo 2023-03-04 16:08:33 +00:00 committed by GitHub
parent 5f2594ed4a
commit ef2d9a520b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 18 deletions

View File

@ -39,16 +39,13 @@ def subscribe(message):
bot.send_message(message.chat.id, "You are subscribed") bot.send_message(message.chat.id, "You are subscribed")
def recheck(): def recheck():
time.sleep(1) time.sleep(60)
send_notification() send_notification()
def send_notification(): def send_notification():
# Inserisci il giorno di oggi
today = datetime.datetime.today().strftime('%A') today = datetime.datetime.today().strftime('%A')
# Print hours tomorrow = (datetime.datetime.today() + datetime.timedelta(days=1)).strftime('%A')
now = datetime.datetime.now() now = datetime.datetime.now()
print(now.strftime("%H:%M"))
finish = False
if today == "Saturday" or today == "Sunday": if today == "Saturday" or today == "Sunday":
print("Today is weekend") print("Today is weekend")
else: else:
@ -61,27 +58,40 @@ def send_notification():
if now.strftime("%H:%M") == "07:50": if now.strftime("%H:%M") == "07:50":
for i in find_document: for i in find_document:
for b in array_username: for b in array_username:
bot.send_message(b, i['School Subject'][today][0]['Subject']) bot.send_message(b, str(i['School Subject']['Monday'][0]['Room']) + ", " + i['School Subject']['Monday'][0]['Teacher'] + ", " + i['School Subject']['Monday'][0]['Subject'] + "\n" + "Successiva: " + str(i['School Subject']['Monday'][1]['Room']) + ", " + i['School Subject']['Monday'][1]['Teacher'] + ", " + i['School Subject']['Monday'][1]['Subject'])
elif now.strftime("%H:%M") == "08:53": recheck()
elif now.strftime("%H:%M") == "8:50":
for i in find_document: for i in find_document:
for b in array_username: for b in array_username:
bot.send_message(b, i['School Subject'][today][1]['Subject']) bot.send_message(b, str(i['School Subject']['Monday'][1]['Room']) + ", " + i['School Subject']['Monday'][1]['Teacher'] + ", " + str(i['School Subject']['Monday'][1]['Subject']) + "\n" + "Successiva: " + str(i['School Subject']['Monday'][2]['Room']) + ", " + i['School Subject']['Monday'][2]['Teacher'] + ", " + i['School Subject']['Monday'][2]['Subject'])
elif now.strftime("%H:%M") == "09:53": recheck()
elif now.strftime("%H:%M") == "9:50":
for i in find_document: for i in find_document:
for b in array_username: for b in array_username:
bot.send_message(b, i['School Subject'][today][2]['Subject']) bot.send_message(b, str(i['School Subject']['Monday'][2]['Room']) + ", " + i['School Subject']['Monday'][2]['Teacher'] + ", " + str(i['School Subject']['Monday'][2]['Subject']) + "\n" + "Successiva: " + str(i['School Subject']['Monday'][3]['Room']) + ", " + i['School Subject']['Monday'][3]['Teacher'] + ", " + i['School Subject']['Monday'][3]['Subject'])
elif now.strftime("%H:%M") == "10:53": recheck()
elif now.strftime("%H:%M") == "11:05":
for i in find_document: for i in find_document:
for b in array_username: for b in array_username:
bot.send_message(b, i['School Subject'][today][3]['Subject']) bot.send_message(b, str(i['School Subject']['Monday'][3]['Room']) + ", " + i['School Subject']['Monday'][3]['Teacher'] + ", " + str(i['School Subject']['Monday'][3]['Subject']) + "\n" + "Successiva: " + str(i['School Subject']['Monday'][4]['Room']) + ", " + i['School Subject']['Monday'][4]['Teacher'] + ", " + i['School Subject']['Monday'][4]['Subject'])
elif now.strftime("%H:%M") == "12:08": recheck()
elif now.strftime("%H:%M") == "12:05":
for i in find_document: for i in find_document:
for b in array_username: for b in array_username:
bot.send_message(b, i['School Subject'][today][4]['Subject']) bot.send_message(b, str(i['School Subject']['Monday'][4]['Room']) + ", " + i['School Subject']['Monday'][4]['Teacher'] + ", " + str(i['School Subject']['Monday'][4]['Subject']) + "\n" + "Successiva: " + str(i['School Subject']['Monday'][5]['Room']) + ", " + i['School Subject']['Monday'][5]['Teacher'] + ", " + i['School Subject']['Monday'][5]['Subject'])
elif now.strftime("%H:%M") == "13:08": recheck()
elif now.strftime("%H:%M") == "13:05":
for i in find_document: for i in find_document:
for b in array_username: for b in array_username:
bot.send_message(b, i['School Subject'][today][5]['Subject']) bot.send_message(b, str(i['School Subject']['Monday'][5]['Room']) + ", " + i['School Subject']['Monday'][5]['Teacher'] + ", " + str(i['School Subject']['Monday'][5]['Subject']))
recheck()
elif now.strftime("%H:%M") == "21:00":
if tomorrow == "Sunday" or tomorrow == "Saturday":
print("Nope")
else:
for i in find_document:
for b in array_username:
bot.send_message(b, i['School Subject'][tomorrow][0]['Subject'] + ", " + i['School Subject'][tomorrow][0]['Teacher'] + "\n" + i['School Subject'][tomorrow][1]['Subject'] + ", " + i['School Subject'][tomorrow][1]['Teacher'] + "\n" + i['School Subject'][tomorrow][2]['Subject'] + ", " + i['School Subject'][tomorrow][2]['Teacher'] + "\n" + i['School Subject'][tomorrow][3]['Subject'] + ", " + i['School Subject'][tomorrow][3]['Teacher'] + "\n" + i['School Subject'][tomorrow][4]['Subject'] + ", " + i['School Subject'][tomorrow][4]['Teacher'] + "\n" + i['School Subject'][tomorrow][5]['Subject'] + ", " + i['School Subject'][tomorrow][5]['Teacher'])
else: else:
recheck() recheck()
@ -90,5 +100,4 @@ now = datetime.datetime.now()
t1 = threading.Thread(target=bot.polling).start() t1 = threading.Thread(target=bot.polling).start()
while True: while True:
print(now.strftime("%H:%M"))
schedule.run_pending() schedule.run_pending()