diff options
author | hellekin <hellekin@cepheide.org> | 2020-11-12 01:10:28 +0100 |
---|---|---|
committer | hellekin <hellekin@cepheide.org> | 2020-11-12 01:10:28 +0100 |
commit | 8d9387cf64929b6467b6ba52f22ca0aa5ed35782 (patch) | |
tree | 37533e75476680ebad4cd1d47e3e578b879726ba /doc/import/LocationsParser.rb | |
parent | b6aeac4d9274f17e748efb3715aa08f4b7c361f2 (diff) | |
parent | 757decefafb5d82557a8b7fa9691f94f19c3207e (diff) | |
download | incommon-map-8d9387cf64929b6467b6ba52f22ca0aa5ed35782.tar.gz |
Merged master
Diffstat (limited to 'doc/import/LocationsParser.rb')
-rw-r--r-- | doc/import/LocationsParser.rb | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/doc/import/LocationsParser.rb b/doc/import/LocationsParser.rb index 3ce79c0..9a8eba5 100644 --- a/doc/import/LocationsParser.rb +++ b/doc/import/LocationsParser.rb @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2020 IN COMMON Collective <collective@incommon.cc> +# +# SPDX-License-Identifier: AGPL-3.0-or-later + #This file parses the data from the "Concertes" and "Dewey" folders #It creates a file "Locations.geojson" which is in the geoJson format to be used with a map @@ -10,6 +14,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 +43,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 +71,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"] |