From 7a9767ffce6a55fd76315ffdcbb9b881a9182f54 Mon Sep 17 00:00:00 2001 From: Julien Wajsberg Date: Sat, 13 Oct 2018 18:35:00 +0200 Subject: [PATCH] Split stations on comma --- flatisfy/filters/metadata.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/flatisfy/filters/metadata.py b/flatisfy/filters/metadata.py index daeecc2..a51798b 100644 --- a/flatisfy/filters/metadata.py +++ b/flatisfy/filters/metadata.py @@ -289,12 +289,24 @@ def guess_stations(flats_list, constraint, config): ) continue - matched_stations = fuzzy_match( - flat_station, - [x.name for x in opendata["stations"]], - limit=10, - threshold=50 - ) + # Weboob modules can return several stations in a comma-separated list. + flat_stations = flat_station.split(',') + # But some stations containing a comma exist, so let's add the initial + # value to the list of stations to check if there was one. + if len(flat_stations) > 1: + flat_stations.append(flat_station) + + matched_stations = [] + for tentative_station in flat_stations: + matched_stations += fuzzy_match( + tentative_station, + [x.name for x in opendata["stations"]], + limit=10, + threshold=50 + ) + + # Keep only one occurrence of each station + matched_stations = list(set(matched_stations)) # Filter out the stations that are obviously too far and not well # guessed