Initial Upload

This commit is contained in:
jodmz521 2026-04-02 10:34:17 -04:00
parent e816005a99
commit b2fce3c122
5 changed files with 147 additions and 0 deletions

14
.msmtprc Normal file
View File

@ -0,0 +1,14 @@
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log
account gmail
host smtp.gmail.com
port 587
from jakesclarion02alerts@gmail.com
user jakesclarion02alerts@gmail.com
password xwhqmgkcjhbyiuck
account default : gmail

29
README.txt Normal file
View File

@ -0,0 +1,29 @@
READ ME FOR WEBPAGE UPDATING CHECKER CREATED BY JACOB DAVIS 1/7/2026
This is a set of scripts that will check the the date and time published on the Clarion02 webpage.
If the time has not updated in 15 minutes, it will send an email to the sender list held in the sendEmailAlert.sh file.
Before running, make sure the appropriate mail utilities are installed.
>>sudo apt install mailutils
You will also need the msmtp packages
>>sudo apt install msmtp msmtp-mta
Next, copy the .msmtprc file to your home directory. It is a hidden file, so if you don't see it in the folder, check that you can see hidden files.
AFTER .msmtprc file is in your home directory, give it appropriate security permissions with:
>>chmod 600 ~/.msmtprc
Next, make sendEmailAlert.sh an executable with (instide the WebPageChecker folder)
>>chmod +x sendEmailAlert.sh
Finally, run the script with
>>python3 WebPageUpdateChecker.py
Other files: There is an email sending script using python that is a bit more complicated but will work as well if you'd rather use that. Just change the subprocess.run() line in the main script.
Other info: This is all being handled through the gmail account I set up specifically to recieve Clarion Alerts. It may be worth changing that to some other address. If that is done, we will need to edit the .msmtprc file.
hgfgdsdsfgh

64
WebPageUpdateChecker.py Normal file
View File

@ -0,0 +1,64 @@
import requests
from bs4 import BeautifulSoup
from bs4.element import NavigableString
import time
import subprocess
URL = "http://clarion02.physics.fsu.edu/~clarion02/index.html"
HEADERS = {
"User-Agent": "Mozilla/5.0 (date-monitor)"
}
previousTime = "time"
def scrape_date_time():
global previousTime
try:
response = requests.get(URL, headers=HEADERS, timeout=10)
response.raise_for_status()
except requests.RequestException as e:
print(f"[ERROR] Request failed: {e}")
return
soup = BeautifulSoup(response.text, "html.parser")
# Find the <p> that contains the date/time and <pre>
p_tag = soup.find("p")
if not p_tag:
print("Date/Time not found (no <p> tag).")
return
date_text_parts = []
for child in p_tag.children:
# Stop when <pre> is encountered
if getattr(child, "name", None) == "pre":
break
if isinstance(child, NavigableString):
text = child.strip()
if text:
date_text_parts.append(text)
if date_text_parts:
date_time = " ".join(date_text_parts)
#print(date_time)
else:
print("Date/Time not found.")
if date_time == previousTime:
#print("ALERT!!!!!!!!!!!!!!!!!!!")
subprocess.run(["./sendEmailAlert.sh"])
#print("Ran the script*******************")
else:
previousTime = date_time
if __name__ == "__main__":
try:
while True:
scrape_date_time()
time.sleep(900)
except KeyboardInterrupt:
print("\nStopped.")

7
sendEmailAlert.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
TO="jakesclarion02alerts@gmail.com,m24b@fsu.edu, mwheeler4@fsu.edu, vtripath@fsu.edu"
SUBJECT="Clarion in alert WEBPAGE NOT UPDATED!!"
BODY="The webpage time has not updated in 15 minutes!"
echo "$BODY" | mail -s "$SUBJECT" $TO

33
sendEmailAlertPython.py Normal file
View File

@ -0,0 +1,33 @@
import smtplib
from email.message import EmailMessage
def send_email_alert():
TO = "jakesclarion02alerts@gmail.com, m24b@fsu.edu, mwheeler4@fsu.edu, vtripath@fsu.edu" # recipient
FROM = "jakesclarion02alerts@gmail.com" # must match Gmail account
PASSWORD = "xwhqmgkcjhbyiuck" # 16-char App Password
msg = EmailMessage()
msg.set_content("The webpage did not update!")
msg['Subject'] = "WEBPAGE NOT UPDATED!!"
msg['From'] = FROM
msg['To'] = TO
try:
print("Connecting to Gmail SMTP...")
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
#print("Logging in...")
smtp.login(FROM, PASSWORD)
#print("Sending email...")
smtp.send_message(msg)
#print("Email sent successfully!")
except smtplib.SMTPAuthenticationError:
#print("[ERROR] Authentication failed. Check your App Password and FROM address.")
except smtplib.SMTPConnectError:
#print("[ERROR] Could not connect to the SMTP server.")
except Exception as e:
#print(f"[ERROR] Other error: {e}")
if __name__ == "__main__":
send_email_alert()
#print("Email sent successfully.")