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