import time
import requests
import difflib

URL = "https://delacruz.belliniseven.ai/20260324.html"

def fetch_html():
    try:
        r = requests.get(URL, timeout=5)
        return r.text.splitlines()
    except Exception as e:
        print(f"[ERROR] {e}")
        return []

def main():
    print(f"Monitoring: {URL}")
    print("Scanning every 1 second... Press CTRL+C to stop.\n")

    previous_lines = []

    while True:
        current_lines = fetch_html()

        if previous_lines:
            diff = difflib.ndiff(previous_lines, current_lines)

            prev_index = 0
            curr_index = 0

            changes = []

            for line in diff:
                code = line[:2]
                text = line[2:]

                if code == "  ":
                    prev_index += 1
                    curr_index += 1

                elif code == "- ":
                    prev_index += 1
                    changes.append(f"- Line {prev_index}: {text}")

                elif code == "+ ":
                    curr_index += 1
                    changes.append(f"+ Line {curr_index}: {text}")

            if changes:
                print("\n====================")
                print(" CHANGED LINES WITH NUMBERS")
                print("====================")
                for c in changes:
                    print(c)
                print("====================\n")

        previous_lines = current_lines
        time.sleep(1)

if __name__ == "__main__":
    main()
