# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys,json,time,datetime
from xlwt import  *
from typing import List
from alibabacloud_sls20201230.client import Client as Sls20201230Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_sls20201230 import models as sls_20201230_models

class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> Sls20201230Client:
        """
        使用AK&SK初始化账号Client
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 您的AccessKey ID,
            access_key_id='xxxxxxxxx',
            # 您的AccessKey Secret,
            access_key_secret='xxxxxxxxx'
        )
        # 访问的域名
        config.endpoint = f'cn-shanghai.log.aliyuncs.com'
        return Sls20201230Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client('accessKeyId', 'accessKeySecret')
        list_project_request = sls_20201230_models.ListProjectRequest()
        # 复制代码运行请自行打印 API 的返回值
        resp =client.list_project(list_project_request)
        print(resp)
        # data=json.dumps(resp.to_map())
        # data = json.loads(data)
        #
        # wb = Workbook(encoding='utf-8')
        # w = wb.add_sheet(u'topic明细', cell_overwrite_ok=True)
        # w.write(0, 0, u"project名称")
        # w.write(0, 1, u"project描述")
        # w.write(0, 2, u"logstore名称")
        # w.write(0, 3, u"logstore创建时间")
        # w.write(0, 4, u"logstore最后更新时间")
        # w.write(0, 5, u"logstore保存时间(天)")
        # excel_row = 1
        # for i in range(len(data['body']['projects'])):
        #     print(data['body']['projects'][i]['projectName'],data['body']['projects'][i]['description'])
        #     list_log_stores_request = sls_20201230_models.ListLogStoresRequest()
        #     # 复制代码运行请自行打印 API 的返回值
        #     resp1=client.list_log_stores('{}'.format(data['body']['projects'][i]['projectName']), list_log_stores_request)
        #     data1 = json.dumps(resp1.to_map())
        #     data1 = json.loads(data1)
        #     for x in range(len(data1['body']['logstores'])):
        #         print(data1['body']['logstores'][x])
        #         # 复制代码运行请自行打印 API 的返回值
        #         resp2=client.get_log_store('{}'.format(data['body']['projects'][i]['projectName']), '{}'.format(data1['body']['logstores'][x]))
        #         data2 = json.dumps(resp2.to_map())
        #         data2 = json.loads(data2)
        #         createTime = time.localtime(data2['body']['createTime'])
        #         createTime = time.strftime("%Y-%m-%d %H:%M:%S", createTime)
        #         lastModifyTime = time.localtime(data2['body']['lastModifyTime'])
        #         lastModifyTime = time.strftime("%Y-%m-%d %H:%M:%S", lastModifyTime)
        #         print(createTime, lastModifyTime, data2['body']['ttl'])
        #         w.write(excel_row, 0, data['body']['projects'][i]['projectName'])
        #         w.write(excel_row, 1, data['body']['projects'][i]['description'])
        #         w.write(excel_row, 2, data1['body']['logstores'][x])
        #         w.write(excel_row, 3, createTime)
        #         w.write(excel_row, 4, lastModifyTime)
        #         w.write(excel_row, 5, data2['body']['ttl'])
        #         excel_row += 1
        # wb.save('logstore明细清单{}.xls'.format((datetime.datetime.now()).strftime("%Y-%m-%d_%H_%M_%S")))


    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client('accessKeyId', 'accessKeySecret')
        list_project_request = sls_20201230_models.ListProjectRequest()
        # 复制代码运行请自行打印 API 的返回值
        await client.list_project_async(list_project_request)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])
最后修改:2022 年 07 月 07 日
如果觉得我的文章对您有用,请随意赞赏!