From 594b2f95ab4714e8b50fd6b1433968a0f90b95ea Mon Sep 17 00:00:00 2001 From: Jan Schutte <4732389+SchutteJan@users.noreply.github.com> Date: Sun, 21 Jul 2024 11:10:25 +0200 Subject: [PATCH] feat: initial bar data import --- data/bars/.gitignore | 2 ++ data/bars/README.md | 43 ++++++++++++++++++++++++++++++++++++ data/bars/insert-bars.sql.j2 | 13 +++++++++++ data/bars/metadata_bars.json | 1 + data/bars/render_template.py | 18 +++++++++++++++ 5 files changed, 77 insertions(+) create mode 100644 data/bars/.gitignore create mode 100644 data/bars/README.md create mode 100644 data/bars/insert-bars.sql.j2 create mode 100644 data/bars/metadata_bars.json create mode 100644 data/bars/render_template.py diff --git a/data/bars/.gitignore b/data/bars/.gitignore new file mode 100644 index 0000000..d752699 --- /dev/null +++ b/data/bars/.gitignore @@ -0,0 +1,2 @@ +bars.json +cafes.json diff --git a/data/bars/README.md b/data/bars/README.md new file mode 100644 index 0000000..9032edd --- /dev/null +++ b/data/bars/README.md @@ -0,0 +1,43 @@ +# Bars + +Verleende exploitatievergunningen horeca met terrasgrenzen en ontheffingen +https://data.amsterdam.nl/data/datasets/GsY50tEkoJKCGw/verleende-exploitatievergunningen-horeca-met-terrasgrenzen-en-ontheffingen?term=Verleende+exploitatievergunningen+horeca+met+terrasgrenzen+en+ontheffingen + +https://api.data.amsterdam.nl/dcatd/datasets/GsY50tEkoJKCGw + + + +## Explore + +```bash +curl 'https://api.data.amsterdam.nl/dcatd/datasets/GsY50tEkoJKCGw' > bars_metadata.json + +# Get the endpoint of the correct data endpoint: +cat bars_metadata.json | jq '."dcat:distribution"[] | select( ."dct:title" == "Exploitatievergunningen")' + +# Download dataset from "wfs" type: +curl 'https://api.data.amsterdam.nl/v1/wfs/horeca/?REQUEST=GetFeature&SERVICE=WFS&version=2.0.0&count=5000&typenames=exploitatievergunning&BBOX=4.58565,52.03560,5.31360,52.48769,urn:ogc:def:crs:EPSG::4326&outputformat=geojson&srsName=urn:ogc:def:crs:EPSG::4326' > bars.json + +# View location names +jq '.features[].properties.zaaknaam' bars.json + +# All types of locations +jq '.features[].properties.zaak_categorie' bars.json | sort -u + +# Locations of a specific type +jq '.features[] | select(.properties.zaak_categorie == "Café") | .properties.zaaknaam' bars.json + +# Some "zaak_categorie" have sub-categories "zaak_specificatie" +# Example: Cafe -> (Cafe, Eetcafe) +jq '.features[] | select(.properties.zaak_categorie == "Onbekend") | .properties.zaak_specificatie' bars.json +``` + +## Import + +```bash +# Filter on Cafes +jq '.features[] | select(.properties.zaak_categorie == "Café")' bars.json > cafes.json + +poetry run python render_template.py + +``` diff --git a/data/bars/insert-bars.sql.j2 b/data/bars/insert-bars.sql.j2 new file mode 100644 index 0000000..d804781 --- /dev/null +++ b/data/bars/insert-bars.sql.j2 @@ -0,0 +1,13 @@ +{% for loc in locations %} +INSERT INTO "locations" ("name", "coordinates", "published", "description", "osm_node_id", "google_place_id", "imageurl", "address_line") +VALUES ( + '{{ loc.properties.zaaknaam | replace("'", "''") }}', + ST_FlipCoordinates(ST_GeomFromGeoJSON('{{ loc.geometry | tojson }}')), + '1', + '{{ loc.properties.zaak_specificatie }}', + NULL, + NULL, + NULL, + '{{ loc.properties.adres | replace("'", "''") }}' +); +{% endfor %} diff --git a/data/bars/metadata_bars.json b/data/bars/metadata_bars.json new file mode 100644 index 0000000..13aebd1 --- /dev/null +++ b/data/bars/metadata_bars.json @@ -0,0 +1 @@ +{"dct:title": "Verleende exploitatievergunningen horeca met terrasgrenzen en ontheffingen", "dct:description": "Naam, adres, categorie, datum, locatie en terrasgrenzen van verleende exploitatievergunningen voor Horeca. \n\nDe opgenomen\u00a0gegevens komen uit het Horeca Informatie Systeem van de gemeente Amsterdam. Hierin wordt informatie over horecazaken en vergunningen bijgehouden.\u00a0 Aan de hier getoonde informatie kunnen geen rechten worden ontleend. De daadwerkelijk afgegeven ontheffingen en vergunningen zijn geldend. U kunt deze opvragen bij de afdeling Vergunningen van het stadsdeel waar de vestiging zich bevind.", "ams:status": "beschikbaar", "dcat:distribution": [{"dct:title": "Weergave op de kaart", "dcat:accessURL": "https://www.amsterdam.nl/ondernemen/horeca/horeca-kaart/", "ams:purl": "https://api.data.amsterdam.nl/dcatd/datasets/GsY50tEkoJKCGw/purls/1HTNDkqQCILyQA", "ams:resourceType": "vis", "ams:distributionType": "web", "dct:modified": "2018-12-04", "dc:identifier": "1HTNDkqQCILyQA", "ams:classification": "public", "dcat:byteSize": 0, "foaf:isPrimaryTopicOf": {"dct:issued": "2016-10-11", "dct:modified": "2018-12-04"}, "dct:license": "cc-by", "@id": "_:d1"}, {"dct:title": "Exploitatievergunningen", "dcat:accessURL": "https://api.data.amsterdam.nl/v1/wfs/horeca/?REQUEST=GetFeature&SERVICE=WFS&version=2.0.0&count=5000&typenames=exploitatievergunning&BBOX=4.58565,52.03560,5.31360,52.48769,urn:ogc:def:crs:EPSG::4326&outputformat=geojson&srsName=urn:ogc:def:crs:EPSG::4326", "ams:purl": "https://api.data.amsterdam.nl/dcatd/datasets/GsY50tEkoJKCGw/purls/1", "ams:resourceType": "data", "ams:distributionType": "api", "ams:serviceType": "wfs", "dct:modified": "2020-06-30", "dc:identifier": "1", "ams:classification": "public", "dcat:byteSize": 0, "foaf:isPrimaryTopicOf": {"dct:issued": "2020-06-30", "dct:modified": "2020-06-30"}, "dct:license": "cc-by", "@id": "_:d2"}, {"dct:title": "Geometrie\u00ebn terrassen", "dcat:accessURL": "https://api.data.amsterdam.nl/v1/wfs/horeca/?REQUEST=GetFeature&SERVICE=WFS&version=2.0.0&count=5000&typenames=exploitatievergunning-terrasgeometrie&BBOX=4.58565,52.03560,5.31360,52.48769,urn:ogc:def:crs:EPSG::4326&outputformat=geojson&srsName=urn:ogc:def:crs:EPSG::4326", "ams:purl": "https://api.data.amsterdam.nl/dcatd/datasets/GsY50tEkoJKCGw/purls/2", "ams:resourceType": "data", "ams:distributionType": "api", "ams:serviceType": "wfs", "dct:modified": "2020-06-30", "dc:identifier": "2", "ams:classification": "public", "dcat:byteSize": 0, "foaf:isPrimaryTopicOf": {"dct:issued": "2020-06-30", "dct:modified": "2020-06-30"}, "dct:license": "cc-by", "@id": "_:d3"}, {"dct:title": "Exploitatievergunningen", "dcat:accessURL": "https://api.data.amsterdam.nl/v1/wfs/horeca/?REQUEST=GetFeature&SERVICE=WFS&version=2.0.0&count=5000&typenames=exploitatievergunning&outputformat=csv&srsName=urn:ogc:def:crs:EPSG::4326", "ams:purl": "https://api.data.amsterdam.nl/dcatd/datasets/GsY50tEkoJKCGw/purls/3", "ams:resourceType": "data", "ams:distributionType": "file", "dcat:mediaType": "text/csv", "dct:modified": "2020-06-30", "dc:identifier": "3", "ams:classification": "public", "dcat:byteSize": 0, "foaf:isPrimaryTopicOf": {"dct:issued": "2020-06-30", "dct:modified": "2020-06-30"}, "dct:license": "cc-by", "@id": "_:d4"}, {"dct:title": "Geometrie\u00ebn terrassen", "dcat:accessURL": "https://api.data.amsterdam.nl/v1/wfs/horeca/?REQUEST=GetFeature&SERVICE=WFS&version=2.0.0&count=5000&typenames=exploitatievergunning-terrasgeometrie&BBOX=4.58565,52.03560,5.31360,52.48769,urn:ogc:def:crs:EPSG::4326&outputformat=csv&srsName=urn:ogc:def:crs:EPSG::4326", "ams:purl": "https://api.data.amsterdam.nl/dcatd/datasets/GsY50tEkoJKCGw/purls/4", "ams:resourceType": "data", "ams:distributionType": "file", "dcat:mediaType": "text/csv", "dct:modified": "2020-06-30", "dc:identifier": "4", "ams:classification": "public", "dcat:byteSize": 0, "foaf:isPrimaryTopicOf": {"dct:issued": "2020-06-30", "dct:modified": "2020-06-30"}, "dct:license": "cc-by", "@id": "_:d5"}], "overheidds:doel": "...", "foaf:isPrimaryTopicOf": {"dct:issued": "2016-12-07", "dct:modified": "2019-01-21"}, "dct:accrualPeriodicity": "day", "dct:temporal": {}, "ams:temporalUnit": "days", "ams:spatialUnit": "specific", "dct:language": "lang1:nl", "ams:owner": "Gemeente Amsterdam", "dcat:contactPoint": {"vcard:fn": "horecavergunningen", "vcard:hasEmail": "horecavergunningen@centrum.amsterdam.nl"}, "dct:publisher": {"foaf:name": "O. Morris", "foaf:mbox": "o.morris@amsterdam.nl"}, "dcat:theme": ["theme:bestuur", "theme:economie-en-toerisme", "theme:cultuur-en-recreatie"], "dcat:keyword": ["Horeca Informatie Systeem", "exploitatie", "horeca", "vergunningen", "terras", "terrascontour", "terrasgrenzen", "geluidsontheffing"], "ams:license": "cc-by", "dct:identifier": "GsY50tEkoJKCGw", "ams:sort_modified": "2020-06-30", "ams:modifiedby": "atlas.employee.plus@amsterdam.nl", "@context": {"ams": "http://datacatalogus.amsterdam.nl/term/", "ckan": "https://ckan.org/terms/", "class": "ams:class#", "dc": "http://purl.org/dc/elements/1.1/", "dcat": "http://www.w3.org/ns/dcat#", "dct": "http://purl.org/dc/terms/", "foaf": "http://xmlns.com/foaf/0.1/", "lang1": "http://id.loc.gov/vocabulary/iso639-1/", "lang2": "http://id.loc.gov/vocabulary/iso639-2/", "org": "ams:org#", "overheid": "http://standaarden.overheid.nl/owms/terms/", "overheidds": "http://standaarden.overheid.nl/owms/terms/ds#", "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs": "http://www.w3.org/2000/01/rdf-schema#", "void": "http://rdfs.org/ns/void#", "skos": "http://www.w3.org/2004/02/skos/core#", "theme": "ams:theme#", "time": "http://www.w3.org/2006/time#", "vcard": "http://www.w3.org/2006/vcard/ns#", "ams:purl": {"@type": "@id"}, "dcat:dataset": {"@container": "@list"}, "dcat:distribution": {"@container": "@set"}, "dcat:keyword": {"@container": "@set"}, "dcat:landingpage": {"@type": "@id"}, "dcat:theme": {"@container": "@set", "@type": "@id"}, "dct:issued": {"@type": "xsd:date"}, "dct:language": {"@type": "@id"}, "dct:modified": {"@type": "xsd:date"}, "foaf:homepage": {"@type": "@id"}, "foaf:mbox": {"@type": "@id"}, "vcard:hasEmail": {"@type": "@id"}, "vcard:hasURL": {"@type": "@id"}, "vcard:hasLogo": {"@type": "@id"}, "ams-dcatd": "https://api.data.amsterdam.nl/dcatd/datasets/"}, "overheid:authority": "overheid:Amsterdam", "@id": "ams-dcatd:GsY50tEkoJKCGw"} diff --git a/data/bars/render_template.py b/data/bars/render_template.py new file mode 100644 index 0000000..86fd781 --- /dev/null +++ b/data/bars/render_template.py @@ -0,0 +1,18 @@ +from jinja2 import Environment, FileSystemLoader +from pathlib import Path +import json + + +env = Environment( + loader=FileSystemLoader("."), +) + + +def main(): + template = env.get_template("insert-bars.sql.j2") + data = json.loads(Path("cafes.json").read_text()) + print(template.render(locations=data)) + + +if __name__ == "__main__": + main()