carom-server/test-client.py

36 lines
989 B
Python
Raw Normal View History

2017-02-09 20:39:09 +01:00
#!/usr/bin/env python3
import argparse
from datetime import datetime
import requests
url = 'http://127.0.0.1:8000/billard/api/v1/location_data/'
token = '7fdc4e8fbe2508b70f73c65c2d05475632e2388a'
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=1, help="the desk number")
args = parser.parse_args()
payload = {
'location_id': 'a7b47b4b-5b63-3b2f-8af0-4b185843f419',
2017-02-10 19:55:31 +01:00
'desk_no': args.desk,
2017-02-09 20:39:09 +01:00
'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)
if __name__ == '__main__':
main()