Getting started with Python Push
This is just a quick guide on how you could send data to fleet-track.org using a python script
Step 1. Got the vars?
vars the you will need to change
token = "0000000000000000000000000000" # fleet-track.org token
vehicle_name = "Toyota" # device name
auth_user = "12423" # fleet-track.org auth_user
Step 2. Python
Up to date version here, feel free to contribute :)
Python Push example: https://github.com/LukeKeam/fleet-track.org-python/blob/main/push.py
import requests
def post_to_server():
try:
token = "0000000000000000000000000000" # fleet-track.org token
vehicle_name = "Toyota" # device name
auth_user = "12423" # fleet-track.org auth_user
utc = "2021-01-03 08:11:20"
latitude = ""
longitude = ""
speed = ""
vehicle_move_stop = ""
vehicle_move_start = ""
alert = ""
# combined
payload = '{{"vehicle_name":"{0}", "utc":"{1}" , "latitude":"{2}", "longitude":"{3}", ' \
'"speed":"{4}", "vehicle_move_stop":"{5}", "vehicle_move_start":"{6}", ' \
'"alert":"{7}"}}'.format(vehicle_name, utc, latitude, longitude, speed, vehicle_move_stop,
vehicle_move_start, alert)
data_to_send = payload
url = 'https://api.fleet-track.org/gps/'
# send data
ssn = requests.Session()
# test
headers = {'content-type': 'application/json', 'Authorization': 'Token {0}'.format(token), 'user': 'Toyota'}
r = ssn.post(url, data=data_to_send, headers=headers)
print("Status code", r.status_code) # 200 is ok, 524 timeout, 400 bad request, 413 payload too large
print('Posted and completed')
print('')
ssn.close()
except Exception as e:
print('post_to_server except', e)
Step 3. Kick ass
Done! and kick some ass