Skip to content

Commit b0bd924

Browse files
committed
[HH] Also scrape geographical location
1 parent 9f0e9a0 commit b0bd924

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

jedeschule/spiders/hamburg.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,29 @@ class HamburgSpider(SchoolSpider):
1010
name = "hamburg"
1111

1212
start_urls = [
13-
"https://geodienste.hamburg.de/HH_WFS_Schulen?SERVICE=WFS&VERSION=1.1.0&REQUEST=GetFeature&typename=de.hh.up:nicht_staatliche_schulen,de.hh.up:staatliche_schulen"
13+
"https://geodienste.hamburg.de/HH_WFS_Schulen?SERVICE=WFS&VERSION=1.1.0&REQUEST=GetFeature&typename=de.hh.up:nicht_staatliche_schulen,de.hh.up:staatliche_schulen&srsname=EPSG:4326"
1414
]
1515

16+
1617
def parse(self, response):
18+
namespaces = {
19+
"gml": "http://www.opengis.net/gml",
20+
}
21+
1722
elem = ET.fromstring(response.body)
1823

1924
for member in elem:
2025
data_elem = {}
2126
for attr in member[0]:
27+
if attr.tag == "{https://registry.gdi-de.org/id/de.hh.up}the_geom":
28+
# This nested entry contains the coordinates that we would like to expand
29+
lon, lat = attr.findtext(
30+
"gml:Point/gml:pos", namespaces=namespaces
31+
).split(" ")
32+
data_elem["lat"] = lat
33+
data_elem["lon"] = lon
34+
continue
35+
# strip the namespace before returning
2236
data_elem[attr.tag.split("}", 1)[1]] = attr.text
2337
yield data_elem
2438

@@ -39,4 +53,6 @@ def normalize(item: Item) -> School:
3953
fax=item.get("fax"),
4054
phone=item.get("schul_telefonnr"),
4155
director=item.get("name_schulleiter"),
56+
latitude=item.get("lat"),
57+
longitude=item.get("lon"),
4258
)

0 commit comments

Comments
 (0)