Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "MBTAclient"
version = "1.1.33"
version = "1.1.34"
description = "A Python client for interacting with the MBTA API"
readme = "README.md"
requires-python = ">=3.12"
Expand All @@ -22,7 +22,6 @@ classifiers = [

[[project.authors]]
name = "Luca Chiabrera"
email = "luca.chiabrera@gmail.com"

[project.urls]
Homepage = "https://github.com/chiabre/MBTAclient"
Expand Down
35 changes: 3 additions & 32 deletions src/mbtaclient/handlers/base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,6 @@ async def _update_scheduling(
self._logger.debug("New MBTA schedules data detected. Processing.")
trips = await self.__process_scheduling(schedulings=mbta_schedules,trips=trips)
self._cache_manager.update_cache(path=params,params=None,data=trips,last_modified=timestamp)

# if self._last_processed_scheduling['timestamp'] != timestamp:
# self._logger.debug("New MBTA schedules data detected. Processing...")
# trips = await self.__process_scheduling(schedulings=mbta_schedules,trips=trips)
# self._last_processed_scheduling['data'] = trips
# self._last_processed_scheduling['timestamp'] = timestamp
# else:
# self._logger.debug("MBTA Schedules data are up-to-date. Skipping processing.")
# trips = self._last_processed_scheduling['data']

if task_predictions:
mbta_predictions, _ = await task_predictions
Expand Down Expand Up @@ -304,10 +295,6 @@ async def _update_details(self, trips: dict[str, Trip]) -> dict[str, Trip]:
mbta_alerts, _ = await task_alerts

for trip_id, trip in trips.items():
# # Assign the trip ID if not already set
# if not trip.mbta_trip and not trip.mbta_trip.id:
# trip.mbta_trip.id = trip_id

# Fetch and assign the MBTA trip if not already set
if not trip.mbta_trip:
mbta_trip, _ = await self._mbta_client.fetch_trip(id=trip_id)
Expand Down Expand Up @@ -374,25 +361,13 @@ def __is_alert_relevant(self, mbta_alert: MBTAAlert, trip: Trip) -> bool:

Returns:
bool: True if the alert is relevant to the given trip, otherwise False.

Relevance is determined based on the following criteria:
- The alert matches the trip's route (route-level alert).
- The alert's informed entity explicitly mentions the trip ID.
- The alert's informed entity is tied to the departure or arrival stops with relevant activities (boarding or exiting).
- The trip's departure or arrival time falls within the alert's active period.
"""

try:

def check_route_level_alert(informed_entity: MBTAAlertsInformedEntity):
"""
Check if the informed entity is a route-level alert matching the trip's route and direction.

Args:
informed_entity (MBTAAlertsInformedEntity): The informed entity to check.

Returns:
bool: True if the entity matches the route-level alert criteria, otherwise False.
"""
return (
informed_entity.route_id == trip.mbta_route.id and
Expand All @@ -407,8 +382,9 @@ def check_route_level_alert(informed_entity: MBTAAlertsInformedEntity):

for informed_entity in mbta_alert.informed_entities:

active_period_start = mbta_alert.active_period_start.replace(tzinfo=None) if mbta_alert.active_period_start else None
active_period_end = mbta_alert.active_period_end.replace(tzinfo=None) if mbta_alert.active_period_end else None
# Safely preserve/assign timezone awareness via .astimezone() instead of stripping it away
active_period_start = mbta_alert.active_period_start.astimezone() if mbta_alert.active_period_start else None
active_period_end = mbta_alert.active_period_end.astimezone() if mbta_alert.active_period_end else None

try:
if (
Expand Down Expand Up @@ -496,18 +472,13 @@ def _filter_and_sort_trips(
if arrival_stop and not arrival_stop.arrival:
continue



# Remove trips that have already departed + REMOVAL_BUFFER_THRESHOLD
if remove_departed and departure_stop:


if trip.has_departed(departure_stop, time_to_departure=departure_stop.time_to_departure.total_seconds(), filtering_grace_period=self.FILTER_GRACE_PERIOD):
continue

# Remove trips that have already arrived + REMOVAL_BUFFER_THRESHOLD
if arrival_stop:

if trip.has_arrived(arrival_stop,time_to_arrival=arrival_stop.time_to_arrival.total_seconds(),filtering_grace_period=self.FILTER_GRACE_PERIOD):
continue

Expand Down
Loading
Loading