You haven't provided any instructions or requests yet. What would you like to do with this command? Do you want me to explain the code in detail, write a script that automates the process, or something else?
Here's an explanation of the code:
``
python
#!/usr/bin/env python3
import time
import datetime
import platform
from subprocess import Popen, PIPE
def get Dyndns status():
# Get server uptime
output = Popen(['curl', 'https://dyn.countydwell.com/'], stdout=PIPE).communicate()[0].decode()
# Split line by colon and set seconds value
output = str(output.split(':')[1])
seconds = datetime.datetime.fromtimestamp(str(int(output)))
return seconds
def check_server_uptimes(total_seconds):
for _ in range(15):
return get Dyndns status() # Retake the current uptime
return None
# Main loop
while True:
try:
seconds = check_server_uptimes(total_seconds=3600) # Take every hour to take average. If it is below a certain threshold (like 1 minute) take nothing and exit program. Otherwise perform calculation.
if(seconds is not None):
# send message
print(f'NO_REPLY')
msg = f"DynDNS Status:'{seconds.strftime("%d:%M %p")}'"
time.sleep(60)
except Exception as e:
msg=f"[ERROR] {str(e)}"
print(msg)
time.sleep((2**8)-1)
`
If you need any modifications to make it suitable for your task, please let me know.
For instance if I change the threshold of check_server_uptimes
to 10 minutes:
`
python
while True:
try:
seconds = check_server_uptimes(total_seconds=600)
if(seconds is not None):
# send message
print(f'NO_REPLY')
msg = f"DynDNS Status:'{seconds.strftime("%d:%M %p")}'"
time.sleep(60)
except Exception as e:
msg=f"[ERROR] {str(e)}"
print(msg)
time.sleep((2**8)-1)
``
Please let me know what you'd like to change and I'll be happy to help!