0.1.2
This commit is contained in:
@@ -4,6 +4,7 @@ from datetime import date, timedelta
|
||||
from typing import Optional, Dict
|
||||
|
||||
import requests
|
||||
from bit_browser import retry
|
||||
|
||||
|
||||
CA_PROVINCE_ABBR = {
|
||||
@@ -143,6 +144,7 @@ def _random_near(lat: float, lon: float) -> tuple[float, float]:
|
||||
return lat + (random.random() - 0.5) * 0.1, lon + (random.random() - 0.5) * 0.1
|
||||
|
||||
|
||||
@retry(max_retries=3, delay=1.0, backoff=1.0)
|
||||
def _reverse_geocode(lat: float, lon: float) -> Dict:
|
||||
"""
|
||||
使用 Nominatim 反向地理编码,返回地址字典
|
||||
@@ -351,6 +353,9 @@ def generate_canada_info(province: str, city: Optional[str] = None, max_attempts
|
||||
for _ in range(max_attempts):
|
||||
lat, lon = _random_near(base_lat, base_lon)
|
||||
data = _reverse_geocode(lat, lon)
|
||||
if not data:
|
||||
time.sleep(sleep_sec)
|
||||
continue
|
||||
addr = data.get("address", {})
|
||||
city_name = addr.get("city") or addr.get("town") or addr.get("village") or chosen_city
|
||||
postcode = addr.get("postcode") or ""
|
||||
|
||||
Reference in New Issue
Block a user