def get_url_for_alert(alert, alerts):
    """
    Gets the url slug for an alert (given the global alerts object obtained from `Alerts.load()`.)

    Note: The alert must be public to have a url slug.

    Will return a date string in the style '3-jun-2021', unless there were already alerts that day, in which case it'll
    append a 1-indexed counter on to the end eg '3-jun-2021-2'. Note that the first alert of the day never has a count.
    """
    alerts_on_this_day = sorted([
        other_alert
        for other_alert in alerts.public
        if other_alert.starts_at_date.as_local_date == alert.starts_at_date.as_local_date
    ])

    if not alerts_on_this_day:
        raise ValueError(f'Alert {alert.id} is not public so does not have a URL')

    # if this is the first alert of the day (or the only alert of the day), then don't include a counter
    if alert == alerts_on_this_day[0]:
        return alert.starts_at_date.as_url

    # count through the alerts that day til we find this one, so we know
    for i, other_alert in enumerate(alerts_on_this_day[1:], start=2):
        if alert == other_alert:
            return f'{alert.starts_at_date.as_url}-{i}'
    raise ValueError(f'Couldnt find alert {alert.id} in public alerts for day')