"""
@author: luojunhui
"""
import time

from aliyun.log import LogClient, GetLogsRequest

access_key_id = "LTAIP6x1l3DXfSxm"
access_key_secret = "KbTaM9ars4OX3PMS6Xm7rtxGr1FLon"
project = "wqsd-video"
log_store = "video-action-log"
endpoint = "cn-hangzhou.log.aliyuncs.com"


def read_log(start_time, end_time, query, topic=""):
    """
    :param topic:
    :param start_time:
    :param end_time:
    :param query:
    :return:
    """
    request = GetLogsRequest(project, log_store, start_time, end_time, topic, query)
    client = LogClient(
        endpoint=endpoint, accessKeyId=access_key_id, accessKey=access_key_secret
    )
    response = client.get_logs(request)
    if response.get_count() > 0:
        log_list = response.get_logs()
        sorted_log_list = sorted(log_list, key=lambda x: x.timestamp)
        first_log = sorted_log_list[0]
        if int(time.time()) - first_log.timestamp > 3 * 24 * 60 * 60:
            return True
        else:
            return False
    else:
        return False
