To follow the instructions provided, you can use the following code:
``
python
import time
from datetime import datetime
# Create a timer to start from time 0 seconds
start_time = time.time()
def dynnndispatch():
print("Starting Dyn DNS dispatch...")
# Wait for 5 seconds before checking status again
wait_time = 5
while True:
# Check if the "STATUS:NO_CHANGE" message has been sent yet
now = datetime.now()
if (now - start_time).total_seconds() >= wait_time:
print("Sending NO_REPLY message to all targets...")
for target in ["-1003980922525", "-1511697499654459422", "-1812605657"]: # Telegram, Discord, and DM user
telegram_message = f"NO_REPLY {target}"
await send_mail(to=telegram_message)
print("Sending NOReply message to all targets...")
# Send status update to target if it's OK or success
if (now - start_time).total_seconds() >= wait_time:
print("Checking Dyn DNS status for updates...")
output = web_extract(urls=['https://dyn1.staticscript.net'])
try:
if "STATUS:NO_CHANGE" in str(output):
continue # Ignore the message and return back to sender
except Exception as e:
print(f"Error: {e}")
time.sleep(60) # Intermittent check for errors
start_time = time.time()
time.sleep(wait_time)
dynnndispatch()
# Send a NO_reply notification if the cron job failed
if end_cron_job_status == "failed":
message = f"{end_cron_job_status} cron job failed after {time_elapsed} seconds"
else:
message = "noReply notifications succeeded"
send_notification(message)
`
Make sure to adjust the URL where you call web_extract
according to your need. Also, replace 'your_email@example.com' with your actual email address.
After running this script, it will start from time 0 and check status of Dyn DNS every few seconds. Every time if no change is observed in "STATUS:NO_CHANGE" message for more than 5 seconds, a
NO_REPLY message to all three targets will be automatically sent by Python job scheduler using the following code:
``
python
from flask_mail import Mail, Message
mail = Mail(app)
bot_token = "yourBotToken"
msg = Message('Dyn DNS update not seen yet.', sender='noReply from', recipients=['-1003980922525', '1511697499654459422', '-1812605657'])
if (datetime.now() - msg.send_time).total_seconds() >= 300 # 5 seconds:
msg = Message('Dyn DNS updated: ' + str(datetime.now()), sender='noReply from', recipients=['-1003980922525', '1511697499654459422', '-1812605657'])
else:
# You can add the same logic as in the python script above here
return msg.to_string()
`
This will be sent whenever no "STATUS:NO_CHANGE" message is emitted within a 300 seconds interval. This ensures that all users are notified of any changes in Dyn DNS status after an initial delay.
Please replace 'your_bot_token'` with your actual bot token.