#!/usr/bin/env python3 import argparse from datetime import datetime import requests url = 'http://127.0.0.1:8000/billard/api/v1/locationdata/' client_id = '28a34fa1-7b62-4b78-8d2a-ada4db4ac6ea' token = '588d0f4c4b8b90b507e6d5c0ea26f0e28b021262' default_desk_id = 2 def main(): parser = argparse.ArgumentParser() parser.add_argument('--on', action="store_true", help="on or of the switch") parser.add_argument('--date', default=datetime.now(), help="the tst to set") parser.add_argument('--desk', default=default_desk_id, help="the desk number") args = parser.parse_args() payload = { 'client_id': client_id, 'desk_no': args.desk, 'tst': args.date.strftime('%Y-%m-%dT%H:%M:%S%Z') } if args.on: payload['on_off'] = 1 else: payload['on_off'] = 0 print(payload) headers = {'Authorization': 'Token ' + token, } r = requests.post(url=url, data=payload, headers=headers) print(r.status_code) print(r.text) if __name__ == '__main__': main()