<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def is_active_trip(feed: "Feed", trip_id: str, date: str) -> bool: """ Return ``True`` if the ``feed.calendar`` or ``feed.calendar_dates`` says that the trip runs on the given date; return ``False`` otherwise. Note that a trip that starts on date d, ends after 23:59:59, and does not start again on date d+1 is considered active on date d and not active on date d+1. This subtle point, which is a side effect of the GTFS, can lead to confusion. Parameters feed : Feed trip_id : string ID of a trip in ``feed.trips`` date : string YYYYMMDD date string Returns ------- boolean ``True`` if and only if the given trip starts on the given date. Notes ----- - This function is key for getting all trips, routes, etc. that are active on a given date, so the function needs to be fast - Assume the following feed attributes are not ``None``: * ``feed.trips`` """

    service = feed._trips_i.at[trip_id, "service_id"]
    # Check feed._calendar_dates_g.
    caldg = feed._calendar_dates_g
    if caldg is not None:
        if (service, date) in caldg.groups:
            et = caldg.get_group((service, date))["exception_type"].iat[0]
            if et == 1:
                return True
            else:
                # Exception type is 2
                return False
    # Check feed._calendar_i
    cali = feed._calendar_i
    if cali is not None:
        if service in cali.index:
            weekday_str = hp.weekday_to_str(hp.datestr_to_date(date).weekday())
            if (
                cali.at[service, "start_date"]
                <= date
                <= cali.at[service, "end_date"]
                and cali.at[service, weekday_str] == 1
            ):
                return True
            else:
                return False
    # If you made it here, then something went wrong
    return False