import os
import sys
sys.path.append(os.path.dirname(sys.path[0]))
from utils.secure_db_client import get_remote_engine


engine = get_remote_engine(
    site_name="us",          # -> database "selection"
    db_type="postgresql_cluster",         # -> 服务端 alias "mysql"
	user="fangxingjun",         # -> 服务端 alias "mysql"
    user_token="5f1b2e9c3a4d7f60"   # 可不传，走默认
)

# site_name = 'us'
# date_type = 'month'
# date_info = '2026-01'
site_name = sys.argv[1]  # 参数1：站点
date_type = sys.argv[2]  # 参数2：类型：week/4_week/month/quarter/day
date_info = sys.argv[3]  # 参数3：年-周/年-月/年-季/年-月-日, 比如: 2022-1
partitions = {
    'site_name': site_name,
    'date_type': date_type,
    'date_info': date_info,
}
cols_list = ['st_key', 'search_term', 'theme_ch', 'theme_en', 'theme_label_ch', 'theme_label_en', 'date_info', 'created_time', 'updated_time']
engine.sqoop_raw_export(
    hive_table='dws_st_theme',
    import_table=f'{site_name}_st_theme_detail_{date_info.replace("-", "_")}',
    partitions=partitions,
    m=1,
    cols=','.join(cols_list)
)

