Compare commits
2 Commits
cccafbe651
...
21be81690f
| Author | SHA1 | Date | |
|---|---|---|---|
| 21be81690f | |||
| 3a301eea2e |
@@ -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)
|
||||
@@ -56,8 +63,15 @@ def get_amap_township(lon, lat, key=AMAP_KEY, max_retries=3):
|
||||
|
||||
def check_gov_township_diff(**context):
|
||||
"""
|
||||
县政府所在乡镇街道比对主任务
|
||||
县政府所在乡镇街道比对主任务,支持从 dag_run.conf 或 params 中传入自定义 amap_key
|
||||
"""
|
||||
dag_run = context.get('dag_run')
|
||||
conf = (dag_run.conf if dag_run else {}) or {}
|
||||
params = context.get('params') or {}
|
||||
amap_key = conf.get('amap_key') or conf.get('key') or params.get('amap_key') or AMAP_KEY
|
||||
amap_key = str(amap_key).strip()
|
||||
|
||||
print(f"[{datetime.now()}] 使用的高德 API Key: {amap_key[:6]}******{amap_key[-4:] if len(amap_key) > 10 else ''}")
|
||||
print(f"[{datetime.now()}] 开始连接 206 ES 集群...")
|
||||
es_client = ElasticSearchClient(host=ES_HOST)
|
||||
|
||||
@@ -89,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", {})
|
||||
@@ -105,10 +124,10 @@ 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_township = get_amap_township(lon, lat)
|
||||
# 2. 调用高德 API 获取 township(传入可配置的 amap_key)
|
||||
amap_township = get_amap_township(lon, lat, key=amap_key)
|
||||
|
||||
# 3. 根据民政部区划代码 mzb_district_code 查询该区域下 has_gov='是' 的街道
|
||||
query_street = {
|
||||
@@ -220,6 +239,9 @@ with DAG(
|
||||
start_date=pendulum.datetime(2024, 1, 1, tz="Asia/Shanghai"),
|
||||
catchup=False,
|
||||
description="县政府所在乡镇街道核验排查(每月1日9点)",
|
||||
params={
|
||||
"amap_key": AMAP_KEY
|
||||
},
|
||||
tags=["poi", "gov", "audit"]
|
||||
) as dag:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user