diff --git a/dags/poi/dag_check_gov_township_diff.py b/dags/poi/dag_check_gov_township_diff.py index c47e773..5c3ac02 100644 --- a/dags/poi/dag_check_gov_township_diff.py +++ b/dags/poi/dag_check_gov_township_diff.py @@ -20,10 +20,11 @@ INDEX_NAME = "administrative_mapping_45" ES_HOST = "192.168.0.206" -def get_amap_township(lon, lat, key=AMAP_KEY, max_retries=3): +def get_amap_township(lon, lat, key=AMAP_KEY, max_retries=5): """ 调用高德逆地理编码接口获取 township (乡镇/街道) https://restapi.amap.com/v3/geocode/regeo?location=lon,lat&extensions=base&roadlevel=0 + 遇 CUQPS_HAS_EXCEEDED_THE_LIMIT (code 10021) 时 sleep 0.2 秒后重试 """ url = "https://restapi.amap.com/v3/geocode/regeo" params = { @@ -47,7 +48,13 @@ def get_amap_township(lon, lat, key=AMAP_KEY, max_retries=3): return str(township[0]).strip() return "" else: - print(f"高德接口返回异常: {data.get('info')}, code: {data.get('infocode')}") + info = str(data.get("info", "")) + infocode = str(data.get("infocode", "")) + print(f"高德接口返回异常: {info}, code: {infocode}") + # 超出并发限制 (10021 / CUQPS_HAS_EXCEEDED_THE_LIMIT) 时等待 0.2 秒后重试 + if infocode == "10021" or "CUQPS_HAS_EXCEEDED_THE_LIMIT" in info: + time.sleep(0.2) + continue except Exception as e: print(f"请求高德逆地理编码失败 (第{attempt+1}次): {e}") time.sleep(0.5) @@ -96,7 +103,12 @@ def check_gov_township_diff(**context): province = source.get("province", "") city = source.get("city", "") - district = source.get("district", "") + district = str(source.get("district", "")).strip() + + # 校验的是县政府驻扎地,如果区域是以“区”结尾(市辖区),直接跳过 + if district.endswith("区"): + continue + mzb_district_code = source.get("mzb_district_code", "") tjj_district_code = source.get("tjj_district_code", "") location = source.get("location", {}) @@ -112,7 +124,7 @@ def check_gov_township_diff(**context): processed_count += 1 if processed_count % 50 == 0: - print(f"已处理 {processed_count} 个区域, 当前发现差异 {len(diff_list)} 条...") + print(f"已处理 {processed_count} 个县/市/旗, 当前发现差异 {len(diff_list)} 条...") # 2. 调用高德 API 获取 township(传入可配置的 amap_key) amap_township = get_amap_township(lon, lat, key=amap_key)