year = int(args[0]) month = int(args[1]) day = int(args[2]) if len(args) > 3: newa_base_time = datetime(year, month, day, int(args[3])) else: newa_base_time = datetime(year, month, day, 23) # otherwise, latest_possible report date is yesterday else: newa_base_time = today - ONE_DAY test_last_day = dateAsInt(newa_base_time) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - criteria = ('bbox', 'county', 'name', 'network', 'sid', 'state') factory = ObsnetDataFactory(options) criteria = factory._validCriteria(options, criteria) metadata = list(factory._parseMetadata(options.metadata)) if 'datasets' not in metadata: metadata.append('datasets') if 'first_hour' not in metadata: metadata.append('first_hour') if 'last_report' not in metadata: metadata.append('last_report') if 'name' not in metadata: metadata.append('name') if 'sid' not in metadata: metadata.append('sid') if 'state' not in metadata: metadata.append('state') if 'ucanid' not in metadata: metadata.append('ucanid') for station in factory.getIndexedStations(metadata, criteria, options.sort_by): if test_index: prev_last_report = station['last_report'] prev_last_day = prev_last_report / 100 if prev_last_day != test_last_day: print test_msg % station else:
sort_by = options.sort_by if len(args) > 0: dump_filepath = os.path.normpath(args[0]) filepath, ext = os.path.splitext(dump_filepath) if ext in ('.txt', '.tsv'): as_tsv_file = True else: as_tsv_file = False else: as_tsv_file = options.as_tsv_file dump_filepath = 'station_index_dump' if as_tsv_file: dump_filepath += '.tsv' else: dump_filepath += '.py' factory = ObsnetDataFactory(options) criteria = factory._validCriteria(options, ('network', 'state')) metadata = factory._parseMetadata(options.metadata) dump_file = open(dump_filepath, 'w') # tab separated values file if as_tsv_file: dump_file.write('\t'.join(metadata)) for station in factory.getIndexedStations(metadata, criteria, sort_by): line = '\t'.join([str(station[key]) for key in metadata]) dump_file.write('\n%s' % line) # importable python object file else: dump_file.write('(') for station in factory.getIndexedStations(metadata, criteria, sort_by): if datasets_as_tuple: station['datasets'] = tuple([ dataset.strip() for dataset in station['datasets'].split(',')