def get_streaming_event():
    try:
        now = datetime.datetime.now()
        streaming_event = Event.objects.filter(public=True,
                                               start_date__lte=now).order_by('-start_date')[0]
        try:
            next_event = streaming_event.get_next()
        except Event.DoesNotExist:
            streaming_event = next_event
        else:
            td = next_event.start_date - now
            if td.days == 0 and 0 < td.seconds < 1800:
                # if there is 30min to next event, take that one
                streaming_event = next_event
        # TODO: if previous event should have ended more than 3 hours ago, don't display the stream
    except __HOLE__:
        return

    return streaming_event
dataset/ETHPy150Open kiberpipa/Intranet/pipa/video/utils.py/get_streaming_event