import os
import time
import datetime
import telegram


import requests



# Telegram bot token and chat ID


# Path to the file and folder to monitor

folder_path = '/'



# Initialize Telegram bot
#bot = telegram.Bot(token=TOKEN)

def check_last_modified():
   # file_last_modified = os.path.getmtime(file_path)
    folder_last_modified = os.path.getmtime(folder_path)

    current_time = time.time()
    #file_last_modified_time = datetime.datetime.fromtimestamp(file_last_modified)
    folder_last_modified_time = datetime.datetime.fromtimestamp(folder_last_modified)

    # if (current_time - file_last_modified) > 10:  # 600 seconds = 10 minutes
    #     # send_telegram_message(f"The file '{file_path}' was last modified longer than 10 minutes ago.")
    #     asyncio.run(send_telegram_message("-1001778433367", f"The file '{file_path}' was last modified longer than 10 minutes ago."))
    #     print(f"'{current_time}' -- The file '{file_path}' was last modified longer than 2 minutes ago.")
    if (current_time - folder_last_modified) > 10:  # 600 seconds = 10 minutes
        message="The hiwar tounsi HLS  was last modified longer than 10 minutes ago."
        base_url = 'https://api.telegram.org/bot5522894419:AAE9CeONlV2lfmUGqbXGZAHC-l1Z90TMuD4/sendMessage?chat_id=-1001778433367&text="{}"'.format(message)
        requests.get(base_url)
        #asyncio.run(send_telegram_message("-1001778433367", f"The folder '{folder_path}' was last modified longer than 10 minutes ago."))
        # send_telegram_message(f"The folder '{folder_path}' was last modified longer than 10 minutes ago.")
        print(f"'{current_time}' -- The folder '{folder_path}' was last modified longer than 2 minutes ago.")
    else:
        datetime_obj = datetime.datetime.fromtimestamp(current_time)
        readable_time = datetime_obj.strftime('%Y-%m-%d %H:%M:%S')
       # asyncio.run(send_telegram_message("-1001778433367", f"'{str(readable_time)}' -- all good"))
        print(f"'{str(readable_time)}' -- all good")

# def send_telegram_message(message):
#     bot.send_message(chat_id=CHAT_ID, text=message)



# Continuously monitor the last modification time every 1 minute
while True:
    check_last_modified()
    time.sleep(300)  # Sleep for 1 minute
