def report(timestamp, vin, data): logger.info('Tracking Callback Server: Report request: Time: %s, VIN: %s, Data: %s.', timestamp, vin, data) # get the vehicle record from the database try: vehicle = Vehicle.objects.get(veh_vin = vin) except Exception as e: logger.error("Tracking Callback Server: Cannot retrieve vehicle '%s' from database. Error: %s", vin, e) return {u'status': 0} location = Location() location.loc_vehicle = vehicle location.loc_time = timestamp for channel in data: key = channel['channel'] value = channel['value'] if key == 'location': location.loc_latitude = value['lat'] location.loc_longitude = value['lon'] location.loc_altitude = value['alt'] elif key == 'speed': location.loc_speed = float(value) elif key == 'odometer': location.loc_odometer = float(value) location.save() return {u'status': 0}
def report(timestamp, vin, data): logger.info( 'Tracking Callback Server: Report request: Time: %s, VIN: %s, Data: %s.', timestamp, vin, data) # get the vehicle record from the database try: vehicle = Vehicle.objects.get(veh_vin=vin) except Exception as e: logger.error( "Tracking Callback Server: Cannot retrieve vehicle '%s' from database. Error: %s", vin, e) return {u'status': 0} location = Location() location.loc_vehicle = vehicle try: location.loc_time = datetime.fromtimestamp(float(timestamp)) except: location.loc_time = timestamp if isinstance(data, str) or isinstance(data, unicode): logger.info('data is string') data = ast.literal_eval(data) for channel in data: key = channel['channel'] value = channel['value'] logger.info('%s: %s', key, value) if key == 'location': location.loc_latitude = value['lat'] location.loc_longitude = value['lon'] location.loc_altitude = value['alt'] elif key == 'speed': location.loc_speed = float(value) elif key == 'odometer': location.loc_odometer = float(value) print 'Saving', location location.save() logger.info('Saved') return {u'status': 0}