from odps import ODPS
# 阿里云odps连接
access_id = 'LTAIWYUujJAm7CbH'
access_key = 'RfSjdiWwED1sGFlsjXv0DlfTnZTG1P'
endpoint = 'http://service.cn.maxcompute.aliyun.com/api'
project_name = 'loghubods'

odps = ODPS(
    access_id=access_id,
    secret_access_key=access_key,
    project=project_name,
    endpoint=endpoint
)


def query_videos(start_idx, limit):
    # 查询视频标题的表现（从阿里云odps中查询）
    sql = f"SELECT DISTINCT a.videoid, a.title, transed_video_path AS video_path FROM loghubods.video_return_top_500 a LEFT JOIN videoods.dim_video b ON      a.videoid = b.videoid LEFT JOIN videoods.wx_video c ON      a.videoid = c.id WHERE a.dt >= 20231001 ORDER BY videoid LIMIT {start_idx}, {limit};"
    result = []
    with odps.execute_sql(sql).open_reader() as reader:
        for record in reader:
            # 处理查询结果
            result.append(record)
    return result
