from datetime import datetime, time, timedelta import pytz from alibabacloud_mts20140618.client import Client as MTSClient from alibabacloud_mts20140618.models import ListJobRequest from alibabacloud_tea_openapi import models from resource.monitor.basic_monitor import BasicMonitor def write_file(content: str, dt: str): print(content) with open(f"/Users/zhao/Desktop/tzld/文档/MPS/mps_monitor_{dt}.txt", "a+") as f: f.write(content) f.write("\n") class MPSMonitor(BasicMonitor): def __init__(self): super().__init__() @classmethod def download_date(cls, dt: datetime, client: MTSClient): dt_str = dt.strftime("%Y%m%d") write_file("任务ID,任务创建时间,任务结束时间,任务状态,时长,模板ID,管道ID,输入文件,输出文件", dt_str) next_page_token = "" start_time = datetime.combine(dt, time.min) end_time = datetime.combine(dt + timedelta(days=1), time.min) while True: request = ListJobRequest( maximum_page_size=100, start_of_job_created_time_range=start_time.astimezone(pytz.UTC).strftime('%Y-%m-%dT%H:%M:%SZ'), end_of_job_created_time_range=end_time.astimezone(pytz.UTC).strftime('%Y-%m-%dT%H:%M:%SZ'), next_page_token=next_page_token ) response = client.list_job(request) body = response.body jobs = body.job_list.job for job in jobs: creation_time = job.creation_time finish_time = job.finish_time state = job.state job_id = job.job_id output = job.output duration = output.properties.duration output_file_info = output.output_file output_file = f"{output_file_info.bucket}:{output_file_info.object}" pipline_id = job.pipeline_id template_id = output.template_id input_file_info = job.input input_file = f"{input_file_info.bucket}:{input_file_info.object}" write_file(f"{job_id},{creation_time},{finish_time},{state},{duration},{template_id},{pipline_id},{input_file},{output_file}", dt_str) next_page_token = body.next_page_token if not next_page_token: break def run(self): config = models.Config( access_key_id=self.access_key_id, access_key_secret=self.access_key_secret, endpoint="mts.cn-hangzhou.aliyuncs.com" ) # client = MTSClient(config) # template_ids = ["02ace648c50f4136afb546adede4eb49", # "19d56171d13b4b679bc057eb42b6563f", # "295ce1741a3e470983c7e1cf303f382e", # "794661a4f1384f6e9642da02f3190313", # "9ad1268fce31499884e2d440105ae51e", # "a7c5593789644fa1a010b579557e7fe2", # "adfcf35bdf3745c18d739dcb08428a80", # "b2098fcbc5534cce9c90d32fc5d5124c", # "bacabb6700564672804d8a84a07531eb", # "cb8429acf24544ff9bada946bc23e643", # "cc963a743d2140f083cace98a02b83b6", # "d34dfbd6ed944eeaad0555f212159eb3", # "e19880ead9ac477bbad75680bd400847", # "f4f25f0668db49c5805c823c61d011a5", # "fcaace386e4241fabddef70e3ce0d2cb" # ] # print("模板ID,模板名,编解码格式,宽*高,编码级别") # for template_id in template_ids: # request = QueryTemplateListRequest( # template_ids=template_id # ) # response = client.query_template_list(request) # for template in response.body.template_list.template: # print(f"{template.id},{template.name},{template.video.codec},{template.video.width}*{template.video.height},{template.video.profile}") # today = datetime(2026, 1, 31, 0, 0, 0) # min_dt = datetime(2025, 12, 1, 0, 0, 0) # tasks = [] # for i in range(0, 1000): # download_dt = today - timedelta(days=i) # if download_dt < min_dt: # break # tasks.append(lambda dt=download_dt, client=MTSClient(config): self.download_date(dt, client)) # # process_tasks(tasks, 15) # self.download_date(dt=datetime(2026, 2, 10, 0, 0, 0), client=MTSClient(config)) if __name__ == '__main__': monitor = MPSMonitor() monitor.run()