track python script

How do you make a python script that uses the track to actuator to track a cube that is near with the property named start and after a certain amount of time it will track to a cube that is near with the property end for a certain amount of time and after that time is up it then tracks to any cube near with the property start.I would like it to use the near sensor.