muizenval

Observe mouse traps remotely
Log | Files | Refs

test-client.py (1158B)


      1 import requests, random
      2 from optparse import OptionParser
      3 
      4 host = "muizenval.tk"
      5 port = 80
      6 
      7 parser = OptionParser()
      8 parser.add_option('-c', '--connect', action="store_true", help='ready to connect')
      9 parser.add_option('-s', '--status', type="choice", choices=[ "idle", "active" ], help='set status')
     10 parser.add_option('-m', '--mac', type='string', help='mac-address to use, otherwise random')
     11 
     12 opt, args = parser.parse_args()
     13 
     14 if (opt.connect is None) == (opt.status is None):
     15 	print("Error: either '--connect' or '--status' has to be specified")
     16 	print()
     17 	parser.print_help()
     18 	exit()
     19 
     20 if opt.mac:
     21 	mac = opt.mac
     22 else:
     23 	mac = ''.join([ random.choice('0123456789ABCDEF') for _ in range(16) ])
     24 
     25 print('using mac:', mac)
     26 
     27 if opt.connect:
     28 	res = requests.post(f'http://{host}:{port}/api/search_connect', json={ 'mac': mac })
     29 	print('->', res.json()['error'])
     30 elif opt.status == 'idle':
     31 	res = requests.post(f'http://{host}:{port}/api/update_status', json={ 'mac': mac, 'status': False })
     32 	print('->', res.json()['error'])
     33 else:
     34 	res = requests.post(f'http://{host}:{port}/api/update_status', json={ 'mac': mac, 'status': True })
     35 	print('->', res.json()['error'])