diff --git a/datasources/connectors/datatourisme.rb b/datasources/connectors/datatourisme.rb index 732bc1f..04df2fb 100644 --- a/datasources/connectors/datatourisme.rb +++ b/datasources/connectors/datatourisme.rb @@ -16,26 +16,18 @@ def setup(kiba) kiba.source(MetadataSource, @job_id, @job_id, nil, MetadataSource::Settings.from_hash({ 'schema' => [ 'datasources/schemas/tags/base.schema.json', + 'datasources/schemas/tags/hosting.schema.json', + 'datasources/schemas/tags/restaurant.schema.json', + 'datasources/schemas/tags/osm.schema.json', ], 'i18n' => [ 'datasources/schemas/tags/base.i18n.json', + 'datasources/schemas/tags/hosting.i18n.json', + 'datasources/schemas/tags/restaurant.i18n.json', + 'datasources/schemas/tags/osm.i18n.json', ] })) - DatatourismeSource.fetch("#{@settings['flow_key']}/#{@settings['key']}") - .select { |data| @source_filter.nil? || data.dig('type', 'value').start_with?(@source_filter) } - .group_by { |h| h.dig('type', 'value') } - .map do |key, data| - destination_id = "#{@job_id}-#{key.split('#').last}" - name = { 'fr' => 'Datatourisme' } - - kiba.source( - self.class.source_class, - @job_id, - destination_id, - name, - self.class.source_class.const_get(:Settings).from_hash(@settings.merge({ 'destination_id' => destination_id, 'datas' => data })), - ) - end + super end end diff --git a/datasources/schemas/tags/osm.i18n.json b/datasources/schemas/tags/osm.i18n.json index 4edd3b6..1efdf75 100644 --- a/datasources/schemas/tags/osm.i18n.json +++ b/datasources/schemas/tags/osm.i18n.json @@ -64,6 +64,18 @@ } } }, + "information": { + "@default": { + "fr": "information" + }, + "values": { + "office": { + "@default:full": { + "fr": "bureau d'information" + } + } + } + }, "natural": { "@default": { "fr": "nature" @@ -95,6 +107,33 @@ "@default:full": { "fr": "station services" } + }, + "church": { + "@default:full": { + "fr": "église" + } + }, + "camping": { + "@default:full": { + "fr": "camping" + } + }, + "picnic_site": { + "@default:full": { + "fr": "aire de pique-nique" + } + } + } + }, + "religion": { + "@default": { + "fr": "religion" + }, + "values": { + "christian": { + "@default:full": { + "fr": "chrétien" + } } } }, diff --git a/datasources/schemas/tags/osm.schema.json b/datasources/schemas/tags/osm.schema.json index c2dca0d..a614af6 100644 --- a/datasources/schemas/tags/osm.schema.json +++ b/datasources/schemas/tags/osm.schema.json @@ -29,6 +29,11 @@ "information" ] }, + "information": { + "enum": [ + "office" + ] + }, "natural": { "enum": [ "bay", @@ -38,7 +43,15 @@ }, "amenity": { "enum": [ - "fuel" + "fuel", + "church", + "camping", + "picnic_site" + ] + }, + "religion": { + "enum": [ + "christian" ] }, "shop": { diff --git a/datasources/sources/datatourisme.rb b/datasources/sources/datatourisme.rb index e81d83c..4705bde 100644 --- a/datasources/sources/datatourisme.rb +++ b/datasources/sources/datatourisme.rb @@ -14,10 +14,8 @@ class DatatourismeSource < Source class Settings < Source::SourceSettings - const :key, String, name: 'key' # API key - const :flow_key, String, name: 'flow_key' # Flow key - const :destination_id, T.nilable(String), name: 'destination_id' # Destination ID - const :datas, T.nilable(T::Array[T::Hash[String, T.untyped]]), name: 'datas' # Datas + const :app_key, String + const :source_id, String end extend T::Generic @@ -27,7 +25,7 @@ def self.fetch(path) url = "https://diffuseur.datatourisme.fr/webservice/#{path}" response = HTTP.follow.get(url) - return [url, response].inspect unless response.status.success? + raise [url, response].inspect unless response.status.success? Set.new(JSON.parse( decompress_gzip(response.body.to_s) @@ -39,25 +37,17 @@ def self.decompress_gzip(data) end def each - if ENV['NO_DATA'] - [] - else - super(@settings.datas) - end + super(ENV['NO_DATA'] ? [] : self.class.fetch("#{@settings.source_id}/#{@settings.app_key}")) end def map_updated_at(feat) feat.dig('updated_at', 'value') end - def map_source(feat) + def map_destination_id(feat) feat.dig('type', 'value').split('#').last end - def map_destination_id(_feat) - @settings.destination_id - end - def map_geometry(feat) { type: 'Point', @@ -65,6 +55,18 @@ def map_geometry(feat) } end + TYPE = HashExcep[{ + # 'Place' => {}, + 'Camping' => { amenity: 'camping' }, + 'Church' => { amenity: 'place_of_worship', religion: 'christian' }, + 'Restaurant' => { amenity: 'restaurant' }, + 'LocalTouristOffice' => { tourism: 'information', information: 'office' }, + 'Museum' => { tourism: 'museum' }, + 'PointOfView' => { tourism: 'viewpoint' }, + 'PicnicArea' => { amenity: 'picnic_site' }, + 'WineCellar' => { tourism: 'wine cellar' }, + }] + def map_tags(feat) { 'name' => { @@ -82,7 +84,7 @@ def map_tags(feat) 'wheelchair' => [feat.dig('wheelchair', 'value')].compact, 'image' => [feat.dig('image', 'value')].compact, 'description' => [feat.dig('description', 'value')].compact, - } + }.merge(TYPE[feat['type']['value'].split('#').last]) end def map_id(feat) @@ -90,7 +92,7 @@ def map_id(feat) end end -# requête SPARQL pour récupérer les données de Datatourisme +# SPARQL query _sparql = <<~SPARQL PREFIX : PREFIX dc: diff --git a/tests/datatourisme/datatourisme_settings_test.rb b/tests/datatourisme/datatourisme_settings_test.rb index fd22843..0c1e041 100644 --- a/tests/datatourisme/datatourisme_settings_test.rb +++ b/tests/datatourisme/datatourisme_settings_test.rb @@ -5,16 +5,16 @@ class TestDatatourismeSettings < Test::Unit::TestCase def test_datatourisme_expected_settings - settings = DatatourismeSource::Settings.new({ key: 'key', flow_key: 'id', destination_id: 'id', datas: [] }) + settings = DatatourismeSource::Settings.new({ app_key: 'app_key', source_id: 'id' }) instance_vars = settings.instance_variables.map(&:to_s) - expected_vars = %w[@key @flow_key] + expected_vars = %w[@app_key @source_id] assert((expected_vars - instance_vars).empty?) end def test_datatourisme_with_unexpected_settings assert_raise(ArgumentError) do - DatatourismeSource::Settings.new({ key: 'key', flow_key: 'id', unexpected: 'unexpected' }) + DatatourismeSource::Settings.new({ app_key: 'app_key', source_id: 'id', unexpected: 'unexpected' }) end end