Skip to content

Commit

Permalink
Exclude bikeracks from projects
Browse files Browse the repository at this point in the history
They are not of interest for now.
  • Loading branch information
phansch committed Sep 16, 2024
1 parent ebde728 commit 647a969
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
9 changes: 9 additions & 0 deletions sync/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion sync/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 20 additions & 2 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
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():
url = "https://www.example.com/projekt/oderberger-strasse-8/"
result = core.project_slug_from_url(url)
assert result == "oderberger-strasse-8"


def test_root_dir():
assert core.root_dir().name == "infravelo-py"

0 comments on commit 647a969

Please sign in to comment.