判断时间范围

    def timeHandl(self, Y_M_D_data, H_data):
        if Y_M_D_data[-1] != '.':
            Y_M_D_data = Y_M_D_data + '.'
        time_data = Y_M_D_data + H_data
        # 时间格式化
        if ':' in H_data:
            timeStruct = time.strptime(time_data, "%d.%m.%Y.%H:%M")
        else:
            timeStruct = time.strptime(time_data, "%d.%m.%Y.%H")
        start_timestamp = int(time.mktime(timeStruct)) + 7 * 60 * 60
        end_timestamp = start_timestamp + 3*3600
        start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(start_timestamp))
        end_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(end_timestamp))
        status = ''
        status_num = 0
        now = time.time()
        if end_timestamp > now > start_timestamp:
            status = "哈哈哈"
            status_num = 1
        elif start_timestamp > now:
            status = "嘿嘿嘿"
            status_num = 0
        elif end_timestamp < now:
            status = "吼吼吼"
            status_num = 2
        return start_time, start_timestamp, end_time, end_timestamp, status, status_num

你可能感兴趣的:(爬虫,python)