You could use the API by the local organization unit, which is VRR for instance.
I wrote something about the VRR-Routing, which possibly may work for other Locations (At leat in NRW):
https://forum.magicmirror.builders/topic/1281/deutsche-bahn-list-of-connections-with-delays/3