feat(poi): 支持通过dag_run.conf或Airflow UI params自定义高德API Key
This commit is contained in:
@@ -56,8 +56,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)
|
||||
|
||||
@@ -107,8 +114,8 @@ def check_gov_township_diff(**context):
|
||||
if processed_count % 50 == 0:
|
||||
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 +227,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