@same_origin
def route_upcoming(route_id):
    route = Route.objects.get_or_404(name=route_id)
    schedule = Schedule.objects.for_today()

    data = {}
    start = ScheduledStop.arrival_now()

    # Filter the next arrivals for 1hour
    # This should limit the results enough so we don't do more work
    qs = ScheduledStop.objects.filter(route_id=route.id,
                                      schedule_id=schedule.id,
                                      arrival__gt=start,
                                      arrival__lt=start + 3600)

    # Optionally accept a stop argument
    if 'stop' in request.args:
        try:
            stop = Stop.objects.get(id=request.args['stop'])
        except (Stop.DoesNotExist, Stop.MultipleObjectsReturned, ValueError):
            pass
        else:
            qs = qs.filter(stop_id=stop.id)

    # Process ordered by arrival - grouped by stop
    for stop in qs.only('stop_id', 'arrival').order_by('arrival'):
        if data not in stop.stop_id:
            data[stop.stop_id] = {
                'refresh': stop.arrival - start,
                'times': []
            }

        if len(data[stop.stop_id]['times']) >= 3:
            continue

        data[stop.stop_id]['times'].append(
            ScheduledStop.seconds_to_timestring(stop.arrival)
        )

    resp = make_response(json.dumps(data))
    resp.cache_control.no_cache = True
    resp.headers['Content-Type'] = 'application/json'

    return resp
dataset/ETHPy150Open shaunduncan/breezeminder/breezeminder/views/marta.py/route_upcoming/swapped operands of `not in`