Skip to content

Instantly share code, notes, and snippets.

@tapanpandita
Last active February 10, 2021 20:46
Show Gist options
  • Save tapanpandita/5c4cfa88a7419c8dc314343cee084bd1 to your computer and use it in GitHub Desktop.
Save tapanpandita/5c4cfa88a7419c8dc314343cee084bd1 to your computer and use it in GitHub Desktop.
import hypertrack
from django.utils import timezone
# Set your API key on the [library](https://github.com/hypertrack/hypertrack-python)
hypertrack.secret_key = '<YOUR_SECRET_KEY>'
# Create a [cluster/fleet](http://docs.hypertrack.io/docs/fleets#create-a-fleet) to add drivers to
fleet = hypertrack.Fleet.create(name="South Delhi")
# Create a [driver](http://docs.hypertrack.io/docs/drivers#create-a-driver) for a specific fleet. A lookup_id is a unique key that you can add to a driver.
driver = hypertrack.Driver.create(fleet_id=fleet.id, name="Tapan Pandita", lookup_id="32fewticsES")
# Create a [customer](http://docs.hypertrack.io/docs/customers#create-a-customer) to whom the delivery is going to be made
customer = hypertrack.Customer.create(name="Rohit")
# Create the [destination](http://docs.hypertrack.io/docs/destinations#create-a-destination) for the customer where the task will be delivered
destination = hypertrack.Destination.create(customer_id=customer.id, address="Vasant Vihar", city="New Delhi", country="India")
# Create a delivery [task](http://docs.hypertrack.io/docs/tasks#create-a-task) at the destination
task = hypertrack.Task.create(action="delivery", destination_id=destination.id)
# Start a [trip](http://docs.hypertrack.io/docs/trips#start-a-trip) with a driver and the array of tasks that the driver will perform
trip = hypertrack.Trip.create(driver_id=driver.id, tasks=[task.id], start_location={"type":"Point","coordinates":[77.161641, 28.562310]})
# Create [editable url](http://docs.hypertrack.io/docs/tasks#create-editable-urls) to share with your customers to allow them to pin their location on the map
editable_url = task.editable_url(editable='once')
tracking_url = editable_url.tracking_url
print tracking_url # => u'https://eta.fyi/bmnou9'
# Post [GPSLogs](http://docs.hypertrack.io/docs/gps-logs#create-a-gpslog) for a trip
hypertrack.GPSLog.create(trip_id=trip.id, location={"type":"Point","coordinates":[77.161641, 28.562310]}, recorded_at=timezone.now().isoformat())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment