#!/bin/env python
# -*- coding: UTF-8 -*-
import sys
import time
import datetime
day_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]))
pass
def line_process(line):
'''处理每行数据
Args:
Returns:
'''
line = line.strip('
')
items = line.split(' ')
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]] = singleday
if len(singleday) == 24:
#print singleday
pass
def file_process(filename):
'''文件处理,按行读取文件,下级函数处理
Args:
Returns:
'''
file = open(filename)
while(1):
line = file.readline()
if not line:
break
line = line.strip("
")
line_process(line)
day_constancy_check()
if __name__ == "__main__":
filename = sys.argv[1]
file_process(filename)