diff --git a/cpc_direct_stations.py b/cpc_direct_stations.py index d887675..3cfa7f6 100755 --- a/cpc_direct_stations.py +++ b/cpc_direct_stations.py @@ -190,7 +190,7 @@ def geocode(address: str, station_name: str, city: str, district: str) -> Option } url = f"https://nominatim.openstreetmap.org/search?{urllib.parse.urlencode(params)}" req = urllib.request.Request(url, headers={"User-Agent": user_agent}) - with urllib.request.urlopen(req, timeout=10) as response: + with urllib.request.urlopen(req, timeout=15) as response: data = json.loads(response.read().decode("utf-8")) if data: return {"lat": float(data[0]["lat"]), "lon": float(data[0]["lon"])} @@ -199,13 +199,13 @@ def geocode(address: str, station_name: str, city: str, district: str) -> Option return None -def add_coordinates(stations: List[Dict[str, str]], delay: float = 1.0, workers: int = 3) -> List[Dict[str, str]]: +def add_coordinates(stations: List[Dict[str, str]], delay: float = 1.0, workers: int = 2) -> List[Dict[str, str]]: """為站點資料加上座標資訊(使用快取+並發查詢)。 Args: stations: 站點列表 delay: 每個查詢間隔秒數(Nominatim 限制約 1 秒) - workers: 並發查詢執行緒數(預設 3,Nominatim 免費版限制) + workers: 並發查詢執行緒數(預設 2,避免 Nominatim 限制) """ cache = load_coords_cache() missing_coords = [] @@ -377,7 +377,7 @@ def main() -> None: parser.add_argument("--out", help="輸出到檔案路徑") parser.add_argument("--coords", action="store_true", help="加上座標資訊(使用 Nominatim OSM API)") parser.add_argument("--delay", type=float, default=1.0, help="座標查詢間隔秒數(預設 1.0)") - parser.add_argument("--workers", type=int, default=3, help="並發查詢執行緒數(預設 3)") + parser.add_argument("--workers", type=int, default=2, help="並發查詢執行緒數(預設 2,避免 Nominatim 限制)") args = parser.parse_args() html = build_query_html(city=args.city, keyword=args.keyword)