1313
1414# Check for required variables
1515if not all ([UPSNAP_URL , UPSNAP_USERNAME , UPSNAP_PASSWORD ]):
16- print ("❌ Error: Missing required environment variables." , flush = True )
16+ print ("Error: Missing required environment variables." , flush = True )
1717 sys .exit (1 )
1818
1919def authenticate ():
20- print ("🔐 Authenticating..." , flush = True )
20+ print ("Authenticating..." , flush = True )
2121 auth_url = f"{ UPSNAP_URL } /api/collections/users/auth-with-password"
2222 auth_data = {"identity" : UPSNAP_USERNAME , "password" : UPSNAP_PASSWORD }
2323 try :
@@ -29,7 +29,7 @@ def authenticate():
2929 return None
3030
3131def get_devices (token ):
32- print ("📃 Getting list of devices..." , flush = True )
32+ print ("Getting list of devices..." , flush = True )
3333 headers = {'Authorization' : f'Bearer { token } ' }
3434 devices_url = f"{ UPSNAP_URL } /api/collections/devices/records"
3535 try :
@@ -40,24 +40,26 @@ def get_devices(token):
4040 print (f"Error retrieving devices: { e } " , flush = True )
4141 return None
4242
43- def wake_device (token , device_id ):
44- print (f"📨 Sending WOL packet to device { device_id } ..." , flush = True )
43+ def wake_device (token , device_id , device_name , device_ip ):
44+ # Log Name and IP
45+ print (f"Sending WOL packet to '{ device_name } ' ({ device_ip } )..." , flush = True )
46+
4547 headers = {'Authorization' : f'Bearer { token } ' }
4648 wake_url = f"{ UPSNAP_URL } /api/upsnap/wake/{ device_id } "
4749 try :
4850 response = requests .get (wake_url , headers = headers )
4951 response .raise_for_status ()
50- print (f"📬 WOL packet sent successfully to device { device_id } ." , flush = True )
52+ print (f"Successfully sent WOL to ' { device_name } ' ." , flush = True )
5153 except requests .RequestException as e :
52- print (f"🧯 Error sending WOL packet to device { device_id } : { e } " , flush = True )
54+ print (f"Error sending WOL packet to ' { device_name } ' : { e } " , flush = True )
5355
5456def main ():
5557 # 1. Initial Delay
5658 if DELAY_MINUTES > 0 :
57- print (f"⌛ Script started. Waiting for { DELAY_MINUTES } minutes..." , flush = True )
59+ print (f"Script started. Waiting for { DELAY_MINUTES } minutes..." , flush = True )
5860 time .sleep (DELAY_MINUTES * 60 )
5961 else :
60- print ("🏃➡️ Script started. Running immediately..." , flush = True )
62+ print ("Script started. Running immediately..." , flush = True )
6163
6264 # 2. Run the Logic
6365 token = authenticate ()
@@ -66,14 +68,17 @@ def main():
6668 devices = get_devices (token )
6769 if devices :
6870 for device in devices .get ("items" , []):
69- wake_device (token , device .get ("id" ))
71+ # Extract details based on the keys you confirmed
72+ dev_id = device .get ("id" )
73+ dev_name = device .get ("name" , "Unknown" )
74+ dev_ip = device .get ("ip" , "No IP" )
75+
76+ wake_device (token , dev_id , dev_name , dev_ip )
7077
7178 # 3. Idle Forever
72- # This keeps the container "Running" so Docker doesn't restart it.
73- # It will only run again if the container is manually restarted or the machine reboots.
74- print ("🛏️ Task complete. Entering idle mode." , flush = True )
79+ print ("Task complete. Entering idle mode." , flush = True )
7580 while True :
76- time .sleep (3600 ) # Sleep for 1 hour blocks to consume 0 CPU
81+ time .sleep (3600 )
7782
7883if __name__ == "__main__" :
7984 main ()
0 commit comments