mirror of
				https://github.com/KevinMidboe/homeChecker.git
				synced 2025-10-29 17:40:26 +00:00 
			
		
		
		
	Added so you can add to cmd prompt if you want to filter out all other names than the name specified.
This commit is contained in:
		
							
								
								
									
										16
									
								
								homeCheck.py
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								homeCheck.py
									
									
									
									
									
								
							@@ -1,8 +1,8 @@
 | 
				
			|||||||
#!/usr/bin/env python3
 | 
					#!/usr/bin/env python3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from socket import *
 | 
					from socket import *
 | 
				
			||||||
from pprint import pprint
 | 
					 | 
				
			||||||
import json
 | 
					import json
 | 
				
			||||||
 | 
					from sys import argv
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Set host name and port
 | 
					# Set host name and port
 | 
				
			||||||
host = '10.0.0.41'
 | 
					host = '10.0.0.41'
 | 
				
			||||||
@@ -10,13 +10,21 @@ port = 12001
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
clientSocket = socket(AF_INET, SOCK_DGRAM)
 | 
					clientSocket = socket(AF_INET, SOCK_DGRAM)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def fetchHTimes(filter=None):
 | 
				
			||||||
    clientSocket.sendto(b'get_times', (host, port))
 | 
					    clientSocket.sendto(b'get_times', (host, port))
 | 
				
			||||||
    message, address = clientSocket.recvfrom(1024)
 | 
					    message, address = clientSocket.recvfrom(1024)
 | 
				
			||||||
    message = message.decode('utf-8')
 | 
					    message = message.decode('utf-8')
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    for item in json.loads(message):
 | 
					    for item in json.loads(message):
 | 
				
			||||||
        print(item['name'].ljust(10) + ': ' + item['time'])
 | 
					        if filter != None and item['name'].lower() == filter:
 | 
				
			||||||
 | 
					            print(item['name'].ljust(10) +': '+ item['time'])
 | 
				
			||||||
 | 
					            break
 | 
				
			||||||
 | 
					        elif filter == None:
 | 
				
			||||||
 | 
					            print(item['name'].ljust(10) +': '+ item['time'])
 | 
				
			||||||
    clientSocket.close()
 | 
					    clientSocket.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
    main()
 | 
					    if argv[-1][-3:] == '.py':
 | 
				
			||||||
 | 
					        fetchHTimes()
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        fetchHTimes(argv[-1])
 | 
				
			||||||
		Reference in New Issue
	
	Block a user