#!/bin/env python
# -*- coding: UTF-8 -*-import time import datetimeday_list = list() day_dict = dict()def day_constancy_check():'''检查日期是否连续, 小时是否全部存在Args:Returns:'''day_list.sort()first_day = ''for i in range(len(day_list)):if first_day != '':input_day = time.strptime(day_list[i], '%Y%m%d')input_date = datetime.datetime(*input_day[:3])input_date = input_date + datetime.timedelta(-1)last_day = input_date.strftime('%Y%m%d')if first_day != last_day or len(day_dict.get(day_list[i])) != 24:print day_list[i]first_day = day_list[i]#print '{0}:{1}'.format(day_list[i], day_dict.get(day_list[i]))passdef line_process(line):'''处理每行数据Args:Returns:'''line = line.strip('\n')items = line.split('\t')if items[0] >= '20130101':if not day_dict.has_key(items[0]):day_list.append(items[0])singleday = day_dict.get(items[0], list())singleday.append(items[1])singleday.sort()day_dict[items[0]] = singledayif len(singleday) == 24:#print singledaypassdef file_process(filename):'''文件处理,按行读取文件,下级函数处理Args:Returns:'''file = open(filename)while(1):line = file.readline()if not line:breakline = line.strip("\n")line_process(line)day_constancy_check()if __name__ == "__main__":file_process("filename")