Skip to content
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

Exclude bikeracks from projects #11

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading