diff --git a/sync/core.py b/sync/core.py index 0eab2d5..d5ed0e2 100644 --- a/sync/core.py +++ b/sync/core.py @@ -11,9 +11,18 @@ class ProjectState(Enum): IN_PLANNING = "in Planung" ENVISAGED = "Vorgesehen" + +def is_project_to_scrape(project): + return without_done_projects(project) and without_bike_racks(project) + + def without_done_projects(project): return project['status'] != ProjectState.DONE.value +def without_bike_racks(project): + return project["types"][0]["type"] != "Anlehnb\u00fcgel" + + def project_slug_from_url(project_url): return project_url.split('/')[-2] diff --git a/sync/runner.py b/sync/runner.py index 12ace4b..e97059a 100644 --- a/sync/runner.py +++ b/sync/runner.py @@ -17,7 +17,7 @@ def run(): print(f"Downloaded {len(all_projects)} projects from the Infravelo API") # Select projects that are not finished yet, to avoid needless scraping - projects_to_scrape = list(filter(core.without_done_projects, all_projects)) + projects_to_scrape = list(filter(core.is_project_to_scrape, all_projects)) print(f"About to scrape {len(projects_to_scrape)} projects.") core.create_project_dirs(projects_to_scrape) diff --git a/tests/test_sync.py b/tests/test_sync.py index 218bfe5..62836f5 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -1,10 +1,27 @@ from sync import core from pathlib import Path + def test_filter(): - p1 = [{ 'status': 'Abgeschlossen' }, { 'status': 'in Bau'}] + p1 = [{"status": "Abgeschlossen"}, {"status": "in Bau"}] result = list(filter(core.without_done_projects, p1)) - assert result == [{ 'status': 'in Bau'}] + assert result == [{"status": "in Bau"}] + + +def test_bike_rack_filter(): + p1 = [ + { + "types": [ + { + "name": "", + "type": "Anlehnb\u00fcgel", + "metrics": [{"name": "Anzahl Stellpl\u00e4tze", "value": "16"}], + } + ] + } + ] + result = list(filter(core.without_bike_racks, p1)) + assert result == [] def test_project_slug_from_url(): @@ -12,5 +29,6 @@ def test_project_slug_from_url(): result = core.project_slug_from_url(url) assert result == "oderberger-strasse-8" + def test_root_dir(): assert core.root_dir().name == "infravelo-py"