carom-server/test-client.py

40 lines
1.1 KiB
Python
Raw Permalink 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/'
2017-02-11 10:32:24 +01:00
client_id = '28a34fa1-7b62-4b78-8d2a-ada4db4ac6ea'
token = '588d0f4c4b8b90b507e6d5c0ea26f0e28b021262'
default_desk_id = 2
2017-02-09 20:39:09 +01:00
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")
2017-02-11 10:32:24 +01:00
parser.add_argument('--desk', default=default_desk_id, help="the desk number")
2017-02-09 20:39:09 +01:00
args = parser.parse_args()
payload = {
2017-02-11 10:32:24 +01:00
'client_id': client_id,
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)
2017-02-11 10:32:24 +01:00
print(r.status_code)
print(r.text)
2017-02-09 20:39:09 +01:00
if __name__ == '__main__':
main()