diff options
author | Nemael <100dragons@gmail.com> | 2020-10-24 11:14:07 +0200 |
---|---|---|
committer | Nemael <100dragons@gmail.com> | 2020-10-24 11:14:07 +0200 |
commit | eca6705b299c5afe2e8ed995529f7afc5559ae0b (patch) | |
tree | e5e6b5a3b154ee2bfd72d2a78438e027e63e8bb0 | |
parent | 383a840c50ca8f6df19677e93357e9dc6c0e043c (diff) | |
download | incommon-map-eca6705b299c5afe2e8ed995529f7afc5559ae0b.tar.gz |
Added sanitization of data, puts instead of null or / data. Also strips trailing whitespaces. It only sanitizes phone_number, website and email because they these data are following a format. Name, address, etc... are not sanitized
-rw-r--r-- | doc/import/LocationsParser.rb | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/doc/import/LocationsParser.rb b/doc/import/LocationsParser.rb index 3ce79c0..ccb165a 100644 --- a/doc/import/LocationsParser.rb +++ b/doc/import/LocationsParser.rb @@ -10,6 +10,18 @@ class Parser @list_of_locations["type"] = "FeatureCollection" @list_of_locations["features"] = [] end + def sanitize(data) + #Sanitize data. Puts "" instead of null in empty data, and puts "" instead of "/" + if (data == nil) + data = "" + end + data = data.strip + res = data + if (data == "/") + res = "" + end + return res + end def parseDeweyFiles(data_file) #Parses the .json files contained in the Dewey folder data = JSON.parse(File.read(data_file)) @@ -27,9 +39,9 @@ class Parser new_item["properties"]["name"] = data[i]["fields"]["name"] new_item["properties"]["description"] = data[i]["fields"]["comment"] new_item["properties"]["entry_number"] = data[i]["pk"] - new_item["properties"]["phone_number"] = data[i]["fields"]["phone"] - new_item["properties"]["website"] = data[i]["fields"]["web"] - new_item["properties"]["email"] = data[i]["fields"]["email"] + new_item["properties"]["phone_number"] = sanitize(data[i]["fields"]["phone"]) + new_item["properties"]["website"] = sanitize(data[i]["fields"]["web"]) + new_item["properties"]["email"] = sanitize(data[i]["fields"]["email"]) new_item["properties"]["address"] = data[i]["fields"]["address"] new_item["properties"]["city"] = "" #No equivalent in Dewey data new_item["properties"]["postal_code"] = "" #No equivalent in Dewey data @@ -55,9 +67,9 @@ class Parser new_item["properties"]["name"] = data[i]["Denomination_FULL"] new_item["properties"]["description"] = data[i]["description"] new_item["properties"]["entry_number"] = data[i]["NumEntr"] - new_item["properties"]["phone_number"] = coord[i]["Tel"] - new_item["properties"]["website"] = coord[i]["Web"] - new_item["properties"]["email"] = coord[i]["Email"] + new_item["properties"]["phone_number"] = sanitize(coord[i]["Tel"]) + new_item["properties"]["website"] = sanitize(coord[i]["Web"]) + new_item["properties"]["email"] = sanitize(coord[i]["Email"]) new_item["properties"]["address"] = coord[i]["Adresse"] new_item["properties"]["city"] = data[i]["INS_COMMUNE"] new_item["properties"]["postal_code"] = coord[i]["Code postal"] |