direc = os.getcwd() fnames = [os.path.join(direc, fn) for fn in listdir('.') if fn[0] != '.'] for fname in fnames: with open(fname, 'r') as f: dct = json.load(f) obs_day = [] for obs in dct['history']['observations']: a = Weather() dt = obs['date'] dt_str = ' '.join( [dt['year'], dt['mon'], dt['mday'], dt['hour'], dt['min']]) a.datetime = datetime.strptime(dt_str, "%Y %m %d %H %M") a.snow = bool(int(obs['snow'])) try: a.humidity = int(obs['hum']) except: a.humidity = 50 a.temperature = float(obs['tempm']) a.precipitation = max(float(obs['precipm']), 0.0) obs_day.append(a) for i in range(len(obs_day)): obs_day[i].datetime = round_time(obs_day[i].datetime, 60 * 60) # round to the nearest hour if len(obs_day) < 24: print 'before:', len(obs_day) obs_day = dedup(obs_day, lambda x: x.datetime.hour) if len(obs_day) < 24: print 'after:', len(obs_day) weather_ls.extend(obs_day)
direc = os.getcwd() fnames = [os.path.join(direc, fn) for fn in listdir('.') if fn[0] != '.'] for fname in fnames: with open(fname, 'r') as f: dct = json.load(f) obs_day = [] for obs in dct['history']['observations']: a = Weather() dt = obs['date'] dt_str = ' '.join([dt['year'], dt['mon'], dt['mday'], dt['hour'], dt['min']]) a.datetime = datetime.strptime(dt_str, "%Y %m %d %H %M") a.snow = bool(int(obs['snow'])) try: a.humidity = int(obs['hum']) except: a.humidity = 50 a.temperature = float(obs['tempm']) a.precipitation = max(float(obs['precipm']), 0.0) obs_day.append(a) for i in range(len(obs_day)): obs_day[i].datetime = round_time(obs_day[i].datetime, 60 * 60) # round to the nearest hour if len(obs_day) < 24: print 'before:', len(obs_day) obs_day = dedup(obs_day, lambda x: x.datetime.hour) if len(obs_day) < 24: print 'after:', len(obs_day) weather_ls.extend(obs_day)