all repos — webpage-monitor @ 1f7c6ae0d2a4eb658d30b70615294e3b7c91131f

more logging
Marco Andronaco andronacomarco@gmail.com
Mon, 30 Jan 2023 13:16:15 +0100
commit

1f7c6ae0d2a4eb658d30b70615294e3b7c91131f

parent

d09fb8f14ccf7f4e8c9bc045d3cb554c63107b5a

1 files changed, 5 insertions(+), 4 deletions(-)

jump to
M Monitor.pyMonitor.py

@@ -1,5 +1,5 @@

import requests -import time +from time import ctime, sleep import smtplib DEFAULT_INTERVAL = 30

@@ -42,12 +42,13 @@ smtp.sendmail(sender_email, recipient_email, msg)

except Exception as e: print(f"Error sending email: {e}") - print(f"{time.ctime()}: started monitoring {url}.") + print(f"{ctime()}: started monitoring {url}.") while True: + print(f"{ctime()}: downloading page.") response = requests.get(url) current_content = response.text if previous_content and previous_content != current_content: - print(f"{time.ctime()}: change detected.") + print(f"{ctime()}: change detected.") send_notification(previous_content, current_content) previous_content = current_content - time.sleep(interval * 60) # wait for `interval` minutes + sleep(interval * 60) # wait for `interval` minutes