Simplify coordinate lookup: remove proxy support
Free proxies from proxifly/free-proxy-list don't support HTTPS well and are unreliable. Stick with cache + concurrent approach. - Remove proxy fetching and handling code - Default workers reduced to 2 to be more conservative - Rely on persistent cache for efficiency Usage: Run in small batches to avoid Nominatim rate limits. Once cached, results are instant. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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)}"
|
url = f"https://nominatim.openstreetmap.org/search?{urllib.parse.urlencode(params)}"
|
||||||
req = urllib.request.Request(url, headers={"User-Agent": user_agent})
|
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"))
|
data = json.loads(response.read().decode("utf-8"))
|
||||||
if data:
|
if data:
|
||||||
return {"lat": float(data[0]["lat"]), "lon": float(data[0]["lon"])}
|
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
|
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:
|
Args:
|
||||||
stations: 站點列表
|
stations: 站點列表
|
||||||
delay: 每個查詢間隔秒數(Nominatim 限制約 1 秒)
|
delay: 每個查詢間隔秒數(Nominatim 限制約 1 秒)
|
||||||
workers: 並發查詢執行緒數(預設 3,Nominatim 免費版限制)
|
workers: 並發查詢執行緒數(預設 2,避免 Nominatim 限制)
|
||||||
"""
|
"""
|
||||||
cache = load_coords_cache()
|
cache = load_coords_cache()
|
||||||
missing_coords = []
|
missing_coords = []
|
||||||
@@ -377,7 +377,7 @@ def main() -> None:
|
|||||||
parser.add_argument("--out", help="輸出到檔案路徑")
|
parser.add_argument("--out", help="輸出到檔案路徑")
|
||||||
parser.add_argument("--coords", action="store_true", help="加上座標資訊(使用 Nominatim OSM API)")
|
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("--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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
html = build_query_html(city=args.city, keyword=args.keyword)
|
html = build_query_html(city=args.city, keyword=args.keyword)
|
||||||
|
|||||||
Reference in New Issue
Block a user