[server]: Overcome IrishRail's broken station classification system
This commit is contained in:
@ -12,8 +12,10 @@ dynamodb = boto3.resource("dynamodb")
|
|||||||
# API URLs
|
# API URLs
|
||||||
irishrail_url = "http://api.irishrail.ie/realtime/realtime.asmx/"
|
irishrail_url = "http://api.irishrail.ie/realtime/realtime.asmx/"
|
||||||
|
|
||||||
# function to fetch Irish Rail station data
|
# function to fetch Irish Rail station data with types
|
||||||
def fetch_train_stations():
|
# this function seems to be missing stations -- the API must have some uncategorised stations that it won't return
|
||||||
|
# unfortunately, this is the only way to categorise stations as the API won't return the station's category
|
||||||
|
def fetch_train_stations_with_type():
|
||||||
api_function = "getAllStationsXML_WithStationType?StationType="
|
api_function = "getAllStationsXML_WithStationType?StationType="
|
||||||
station_types = ["M", "S", "D"]
|
station_types = ["M", "S", "D"]
|
||||||
stations = []
|
stations = []
|
||||||
@ -38,6 +40,30 @@ def fetch_train_stations():
|
|||||||
|
|
||||||
return stations
|
return stations
|
||||||
|
|
||||||
|
# function to fetch Irish Rail station data without types
|
||||||
|
def fetch_train_stations():
|
||||||
|
api_function = "getAllStationsXML"
|
||||||
|
stations = []
|
||||||
|
|
||||||
|
stations_xml = requests.get(irishrail_url + api_function).text
|
||||||
|
stations_json = json.loads(json.dumps(xmltodict.parse(stations_xml)))
|
||||||
|
|
||||||
|
for station in stations_json["ArrayOfObjStation"]["objStation"]:
|
||||||
|
stations.append({
|
||||||
|
"objectID": "IrishRailStation-" + station["StationCode"],
|
||||||
|
"objectType": "IrishRailStation",
|
||||||
|
"latitude": station["StationLatitude"],
|
||||||
|
"longitude": station["StationLongitude"],
|
||||||
|
|
||||||
|
"trainStationID": station["StationId"],
|
||||||
|
"trainStationCode": station["StationCode"],
|
||||||
|
"trainStationAlias": station["StationAlias"],
|
||||||
|
"trainStationDesc": station["StationDesc"],
|
||||||
|
})
|
||||||
|
|
||||||
|
return stations
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# function to fetch Luas stops data
|
# function to fetch Luas stops data
|
||||||
def fetch_luas():
|
def fetch_luas():
|
||||||
@ -169,4 +195,4 @@ def lambda_handler(event, context):
|
|||||||
|
|
||||||
if "__main__" == __name__:
|
if "__main__" == __name__:
|
||||||
data = fetch_train_stations() + fetch_luas() + fetch_gtfs()
|
data = fetch_train_stations() + fetch_luas() + fetch_gtfs()
|
||||||
print(json.dumps(data))
|
print(json.dumps(data))
|
||||||
|
Reference in New Issue
Block a user