-
Notifications
You must be signed in to change notification settings - Fork 18
Reimplement Berlin and Brandenburg spiders #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
k-nut
merged 6 commits into
Datenschule:main
from
SimonMand:rework_berlin_and_brandenburg_spiders
Jul 6, 2025
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7f4be87
Reworked 2 spiders + tests
SimonMand aea2b88
Removed exception handling
SimonMand 822f3ab
Added empty line
SimonMand 9a8f25a
PR comments: removed utils and added to test workflow
SimonMand 06835ca
Added prints to the RUN commands
SimonMand ba9489f
Updated test_changes shell file
SimonMand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import requests | ||
|
|
||
| from jedeschule.utils import singleton | ||
| from jedeschule.utils.utils import singleton | ||
|
|
||
|
|
||
| @singleton | ||
|
|
||
Empty file.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import json | ||
|
|
||
| from scrapy.http import Response | ||
|
|
||
|
|
||
| def parse_geojson_features(response: Response): | ||
k-nut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| geojson = json.loads(response.text) | ||
|
|
||
| for feature in geojson.get("features", []): | ||
| properties = feature.get("properties", {}) | ||
| coords = feature.get("geometry", {}).get("coordinates", []) | ||
|
|
||
| properties["lon"] = coords[0] | ||
| properties["lat"] = coords[1] | ||
|
|
||
|
|
||
| yield properties | ||
Empty file.
k-nut marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import unittest | ||
| from scrapy.http import TextResponse | ||
| from jedeschule.spiders.berlin import BerlinSpider | ||
|
|
||
|
|
||
| class TestBerlinSpider(unittest.TestCase): | ||
| def test_parse(self): | ||
| json_response = """ | ||
| { | ||
| "type": "FeatureCollection", | ||
| "features": [ | ||
| { | ||
| "type": "Feature", | ||
| "id": "schulen.01A04", | ||
| "geometry": { | ||
| "type": "Point", | ||
| "coordinates": [13.33391576, 52.52672359] | ||
| }, | ||
| "geometry_name": "geom", | ||
| "properties": { | ||
| "bsn": "01A04", | ||
| "schulname": "Berlin-Kolleg", | ||
| "schulart": "Kolleg", | ||
| "traeger": "öffentlich", | ||
| "schultyp": "Andere Schule", | ||
| "bezirk": "Mitte", | ||
| "ortsteil": "Moabit", | ||
| "plz": "10551", | ||
| "strasse": "Turmstraße", | ||
| "hausnr": "75", | ||
| "telefon": "+49 30 901838210", | ||
| "fax": "+49 30 901838222", | ||
| "email": "sekretariat@berlin-kolleg.de", | ||
| "internet": "https://www.berlin-kolleg.de", | ||
| "schuljahr": "2024/25" | ||
| }, | ||
| "bbox": [ | ||
| 13.33391576, | ||
| 52.52672359, | ||
| 13.33391576, | ||
| 52.52672359 | ||
| ] | ||
| } | ||
| ], | ||
| "totalFeatures": 925, | ||
| "numberMatched": 925, | ||
| "numberReturned": 1, | ||
| "timeStamp": "2025-06-13T14:59:35.045Z", | ||
| "crs": { | ||
| "type": "name", | ||
| "properties": { | ||
| "name": "urn:ogc:def:crs:EPSG::4326" | ||
| } | ||
| }, | ||
| "bbox": [ | ||
| 13.33391576, | ||
| 52.52672359, | ||
| 13.33391576, | ||
| 52.52672359 | ||
| ] | ||
| } | ||
| """ | ||
|
|
||
| spider = BerlinSpider() | ||
| response = TextResponse( | ||
| url="http://test_webserver.com", | ||
| body=json_response.encode("utf-8"), | ||
| encoding="utf-8", | ||
| ) | ||
|
|
||
| schools = list(spider.parse(response)) | ||
| self.assertEqual(len(schools), 1) | ||
|
|
||
| school = schools[0] | ||
| self.assertAlmostEqual(school["lon"], 13.33391576) | ||
| self.assertAlmostEqual(school["lat"], 52.52672359) | ||
| self.assertEqual(school["bsn"], "01A04") | ||
| self.assertEqual(school["schulname"], "Berlin-Kolleg") | ||
| self.assertEqual(school["plz"], "10551") | ||
| self.assertEqual(school["strasse"], "Turmstraße") | ||
| self.assertEqual(school["hausnr"], "75") | ||
| self.assertEqual(school["telefon"], "+49 30 901838210") | ||
| self.assertEqual(school["fax"], "+49 30 901838222") | ||
| self.assertEqual(school["email"], "sekretariat@berlin-kolleg.de") | ||
| self.assertEqual(school["internet"], "https://www.berlin-kolleg.de") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import unittest | ||
| from scrapy.http import TextResponse | ||
| import json | ||
|
|
||
| from jedeschule.spiders.brandenburg import BrandenburgSpider | ||
|
|
||
|
|
||
| class TestBrandenburgSpider(unittest.TestCase): | ||
|
|
||
| def test_parse(self): | ||
| json_text = json.dumps({ | ||
| "type": "FeatureCollection", | ||
| "name": "Schul_Standorte", | ||
| "features": [ | ||
| { | ||
| "type": "Feature", | ||
| "properties": { | ||
| "schul_nr": "100020", | ||
| "schulname": "Grundschule Forst Mitte", | ||
| "strasse_hausnr": "Max-Fritz-Hammer-Straße 15", | ||
| "plz": "03149", | ||
| "ort": "Forst (Lausitz)", | ||
| "telefonnummer": "(03562) 7163", | ||
| "faxnummer": "(03562) 691288", | ||
| "dienst_email": "s100020@schulen.brandenburg.de", | ||
| "homepage": "http://www.grundschule-forst-mitte.de", | ||
| "schulamtname": "Staatliches Schulamt Cottbus", | ||
| "kreis": "Spree-Neiße", | ||
| "schulform_kurzbez": "G", | ||
| "schulform": "Grundschule", | ||
| "traeger": "Gemeinde", | ||
| "schultraeger_grp": "o", | ||
| "schueler": "288 (Stand: 2022)", | ||
| "besonderheiten_sl": "(763),(561),(132),(201)", | ||
| "besonderheiten": [ | ||
| "Einstiegsphase Startchancen", | ||
| "Schule mit Nutzung Schul-Cloud Brandenburg", | ||
| "verlässliche Halbtagsschule und Hort", | ||
| "FLEX - Optimierung des Schulanfangs" | ||
| ], | ||
| "studienseminar": "2", | ||
| "fremdsprachen": ["Englisch"], | ||
| "fremdsprachen_sl": "(EN)", | ||
| "fremdsprachen_timestmp": "(Schuljahr: 2020/2021)" | ||
| }, | ||
| "geometry": { | ||
| "type": "Point", | ||
| "coordinates": [14.651148207215728, 51.74023651973522] | ||
| } | ||
| } | ||
| ] | ||
| }) | ||
|
|
||
| spider = BrandenburgSpider() | ||
| response = TextResponse( | ||
| url="http://test_webserver.com", | ||
| body=json_text.encode("utf-8"), | ||
| encoding="utf-8", | ||
| ) | ||
|
|
||
| results = list(spider.parse(response)) | ||
|
|
||
| self.assertEqual(len(results), 1) | ||
| school = results[0] | ||
|
|
||
| self.assertAlmostEqual(school["lat"], 51.74023651973522) | ||
| self.assertAlmostEqual(school["lon"], 14.651148207215728) | ||
|
|
||
| self.assertEqual(school["schul_nr"], "100020") | ||
| self.assertEqual(school["schulname"], "Grundschule Forst Mitte") | ||
| self.assertEqual(school["plz"], "03149") | ||
| self.assertEqual(school["ort"], "Forst (Lausitz)") | ||
| self.assertEqual(school["dienst_email"], "s100020@schulen.brandenburg.de") | ||
| self.assertEqual(school["schulform"], "Grundschule") | ||
| self.assertEqual(school["traeger"], "Gemeinde") | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.