Created
December 6, 2025 17:04
-
-
Save Proteusiq/40a2c5dbe10ed3da6c8cb33d0852ab77 to your computer and use it in GitHub Desktop.
navigate json
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
| #!/usr/bin/env -S uv run --quiet --script | |
| # /// script | |
| # requires-python = ">=3.12" | |
| # dependencies = [ | |
| # "httpx", | |
| # "jmespath", | |
| # "rich", | |
| # ] | |
| # /// | |
| from typing import Any | |
| from httpx import Client | |
| type AnyDict = dict[str, Any] | |
| def get_estates(*, base_url: str, url: str, params: AnyDict) -> AnyDict: | |
| with Client( | |
| base_url=base_url, | |
| headers={"User-Agent": "Prayson Daniel<praysonpi@gmail.com>"}, | |
| ) as requests: | |
| response = requests.get(url, params=params) | |
| assert response.raise_for_status() | |
| return response.json() | |
| if __name__ == "__main__": | |
| import jmespath | |
| from rich.console import Console | |
| from rich.table import Table | |
| base_url = "https://api.boligsiden.dk" | |
| url = "/search/list/cases" | |
| params = { | |
| "addressTypes": ( | |
| "villa,condo,terraced house,holiday house,cooperative," | |
| "farm,hobby farm,full year plot,villa apartment," | |
| "holiday plot,houseboat" | |
| ), | |
| "sortBy": "totalTimeOnMarket", | |
| "sortAscending": "true", | |
| "per_page": 50, | |
| "page": 5, | |
| } | |
| results = get_estates(base_url=base_url, url=url, params=params) | |
| # get road names | |
| road_names = jmespath.search("cases[].address[].roadName", results) | |
| # estate descirptions | |
| estate_descriptions = jmespath.search("cases[].image[].imageSources[].alt", results) | |
| # show off | |
| console = Console() | |
| table = Table(show_lines=False) | |
| table.add_column("Road", style="bold cyan", no_wrap=True) | |
| table.add_column("Estate description", style="white") | |
| for road_name, estate_description in zip( | |
| road_names, estate_descriptions, strict=True | |
| ): | |
| table.add_row(road_name, estate_description) | |
| console.print(table) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment