Create a simple connected railway network between all train stations

As a part of my work for the student university team, I must create a simple connected railway network between all train stations.

I have been using OpenRailwayMap data and Python API to query the data. My main problem is that the network is too complex for my task. For instance, for any of the train stations, instead of all the rails there, I just need one railway since I am interested in going to that station. For instance, I need one rail going through the station, as shown in the example below.

https://preview.redd.it/ilf6t8t7nzce1.png?width=1845&format=png&auto=webp&s=1cd928837ab08139e2616585559e09622d931346

Does anyone know how I can do that?
Another probelm that I have is connectivity. I have tried using the Shapely library to fix the connectivity. However, I still can't create a single graph in many cases because the railways are misconnected by a few meters in a random direction, or they are just missing because of bad data. For instance, here:

https://preview.redd.it/zxxwxdjmnzce1.png?width=1713&format=png&auto=webp&s=bc904c4b618a20939ae7dc376f8bbf645891b9ba

How should I fix that without using the endpoints of lines (because it is slow and can connect some arallel lines)?