Skip to content

Commit 2b8e1d8

Browse files
authored
Merge pull request #25 from eniehack/feat/script-typer
script周りの修正
2 parents 8c4be6a + d025dee commit 2b8e1d8

File tree

5 files changed

+71
-36
lines changed

5 files changed

+71
-36
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ Thumbs.db
2020
# Vite
2121
vite.config.js.timestamp-*
2222
vite.config.ts.timestamp-*
23+
24+
atm*.json
25+
bank*.json
26+
convenience*.json
27+
!static/atm.json
28+
!static/bank.json
29+
!static/convenience.json

script/generate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ uv run -- quackosm \
3131
--work-dir "$QUACKOSM_WORKDIR" \
3232
"$PBF_FILE"
3333

34-
uv run src/atmjsongen/main.py --parquet "$GEOPARQUET_FILE" --geojson_dir .
34+
uv run src/atmjsongen/main.py "$GEOPARQUET_FILE"

script/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ authors = [
88
dependencies = [
99
"geopandas>=1.0.1",
1010
"quackosm[cli]>=0.12.1",
11-
"classopt>=0.2.1",
11+
"typer>=0.17.3",
1212
]
1313
readme = "README.md"
1414
requires-python = ">= 3.12"
1515

16-
[dependencies-groups]
16+
[dependency-groups]
1717
dev = [
18-
"ruff>=0.8.6",
18+
"ruff>=0.14.10",
1919
]
2020

2121
[build-system]

script/src/atmjsongen/main.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
import quackosm as qosm
2-
from argparse import ArgumentParser
31
from typing import Callable
42
from pathlib import Path
53
import geopandas
6-
from classopt import classopt, config
7-
from time import strftime
4+
import typer
85

96

10-
@classopt
11-
class CLIOpt:
12-
parquet: Path = config(long=True)
13-
geojson_dir: Path = config(long=True)
14-
157
def get_sometag(target_tag: str) -> Callable[dict, str | None]:
168
def func(tags):
179
if target_tag in tags:
1810
return tags[target_tag]
1911
else:
2012
return None
13+
2114
return func
2215

16+
2317
def is_atm(tags):
2418
if "amenity" in tags and tags["amenity"] == "atm":
2519
return True
@@ -28,47 +22,56 @@ def is_atm(tags):
2822
else:
2923
return False
3024

25+
3126
def is_bank(tags):
3227
if "amenity" in tags and tags["amenity"] == "bank":
3328
return True
3429
else:
3530
return False
3631

32+
3733
def is_convenience(tags):
3834
if "shop" in tags and tags["shop"] == "convenience":
3935
return True
4036
return False
4137

38+
4239
def get_openinghours(tags):
4340
atm_opening = get_sometag("opening_hours:atm")(tags)
4441
if atm_opening is None:
4542
return get_sometag("opening_hours")(tags)
4643
return atm_opening
4744

4845

49-
if __name__ == "__main__":
50-
# argparser = ArgumentParser()
51-
# argparser.add_argument("-f", "--parquet", type=Path)
52-
# argparser.add_argument("-t", "--geojson_dir", type=Path)
53-
# argparser.parse_args()
54-
opt: CLIOpt = CLIOpt.from_args()
55-
56-
gdf = geopandas.read_parquet(opt.parquet)
46+
def main(parquet: Path, geojson_dir: Path = Path.cwd()):
47+
gdf = geopandas.read_parquet(parquet)
5748
gdf["tags"] = gdf["tags"].apply(lambda l: {i[0]: i[1] for i in l})
5849
gdf["brand"] = gdf["tags"].apply(get_sometag("brand"))
5950
gdf["name"] = gdf["tags"].apply(get_sometag("name"))
6051
gdf["atm"] = gdf["tags"].apply(is_atm)
6152
gdf["bank"] = gdf["tags"].apply(is_bank)
6253
gdf["convenience"] = gdf["tags"].apply(is_convenience)
6354
gdf["opening_hours"] = gdf["tags"].apply(get_openinghours)
55+
6456
gdf.geometry = gdf.representative_point()
6557
gdf.geometry = gdf.geometry.set_precision(grid_size=0.0000001)
58+
6659
atm_gdf = gdf[gdf["atm"]]
6760
atm_gdf = atm_gdf[["feature_id", "brand", "name", "opening_hours", "geometry"]]
68-
atm_gdf.to_file(opt.geojson_dir / f"atm.json", driver="GeoJSON")
61+
atm_gdf.to_file(geojson_dir / "atm.json", driver="GeoJSON", separator=(",", ":"))
62+
6963
bank_gdf = gdf[gdf["bank"] & ~gdf["atm"]]
7064
bank_gdf = bank_gdf[["feature_id", "brand", "name", "opening_hours", "geometry"]]
71-
bank_gdf.to_file(opt.geojson_dir / f"bank.json", driver="GeoJSON")
65+
bank_gdf.to_file(geojson_dir / "bank.json", driver="GeoJSON", separator=(",", ":"))
66+
7267
convenience_gdf = gdf[gdf["convenience"] & ~gdf["atm"]]
73-
convenience_gdf = convenience_gdf[["feature_id", "brand", "name", "opening_hours", "geometry"]]
74-
convenience_gdf.to_file(opt.geojson_dir / f"convenience.json", driver="GeoJSON")
68+
convenience_gdf = convenience_gdf[
69+
["feature_id", "brand", "name", "opening_hours", "geometry"]
70+
]
71+
convenience_gdf.to_file(
72+
geojson_dir / "convenience.json", driver="GeoJSON", separator=(",", ":")
73+
)
74+
75+
76+
if __name__ == "__main__":
77+
typer.run(main)

script/uv.lock

Lines changed: 36 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)