Extract common download utils
This commit is contained in:
parent
6ddb3d2121
commit
3b9ad11d71
9 changed files with 152 additions and 161 deletions
|
|
@ -10,6 +10,17 @@ import polars as pl
|
|||
NAPTAN_CSV_URL = "https://naptan.api.dft.gov.uk/v1/access-nodes?dataFormat=csv"
|
||||
|
||||
|
||||
STOP_TYPES = {
|
||||
'AIR': "Airport",
|
||||
'FTD': "Ferry",
|
||||
"RSE": "Rail station",
|
||||
"BCT": "Bus stop",
|
||||
"BCE": "Bus station",
|
||||
"TXR": "Taxi rank",
|
||||
"TMU": "Metro or Tram stop",
|
||||
}
|
||||
|
||||
|
||||
def download_naptan(output: Path) -> None:
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
|
@ -26,10 +37,11 @@ def download_naptan(output: Path) -> None:
|
|||
pl.col("Longitude").cast(pl.Float64, strict=False),
|
||||
)
|
||||
.drop_nulls(subset=["Latitude", "Longitude"])
|
||||
.filter(pl.col("StopType").is_in(list(STOP_TYPES.keys())))
|
||||
.select(
|
||||
pl.col("ATCOCode").alias("id"),
|
||||
pl.col("CommonName").alias("name"),
|
||||
pl.col("StopType").alias("category"),
|
||||
pl.col("StopType").replace(STOP_TYPES).alias("category"),
|
||||
pl.col("Latitude").alias("lat"),
|
||||
pl.col("Longitude").alias("lng"),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue