def create_trips(self, data, **kwargs):
        self.trip_mapping = {}

        count = 0
        for row in data:
            if count % 500 == 0:
                print 'Checkpoint %s' % count
            count += 1

            try:
                route_id = int(row['route_id'])
                svc_id = int(row['service_id'])
                trip_id = int(row['trip_id'])
                shape_id = int(row['shape_id'])

                self.trip_mapping[trip_id] = {
                    'route_id': route_id,
                    'schedule_id': svc_id,
                    'direction': row['direction_id'],
                    'headsign': row['trip_headsign'],
                    'block': row['block_id'],
                }
            except ValueError:
                print 'WARNING: Could not parse route/service/trip/shape id of trip %s' % row
                continue

            try:
                route = Route.objects.get(id=route_id)
            except Route.DoesNotExist:
                print 'WARNING: No route for id %s' % route_id
                continue

            try:
                schedule = Schedule.objects.get(id=svc_id)
            except Schedule.DoesNotExist:
                print 'WARNING: No schedule for id %s' % svc_id
                schedule = None

            try:
                shape = Shape.objects.get(id=shape_id)
            except Shape.DoesNotExist:
                print 'WARNING: No shape for id %s' % shape_id
                shape = None

            defaults = {
                'route': route,
                'schedule': schedule,
                'shape': shape,
                'headsign': self.allcaps(row['trip_headsign']),
                'direction': row['direction_id'],
                'block': row['block_id']
            }

            try:
                Trip(id=trip_id, **defaults).save()
            except:
                print 'Trip exists'
                continue
dataset/ETHPy150Open shaunduncan/breezeminder/breezeminder/management/commands/import_marta_data.py/ImportMartaData.create_trips/original