def import_main(): # NOTE: This function is referenced from setup.py entry_points """Entry point for the offline import command.""" options = _parse_args(sys.argv) importer_name = options.importer_name filenames = options.filenames if importer_name not in _importer_defs: print >> sys.stderr, 'Unknown importer: %r.\n%s' % ( importer_name, _importer_list_msg()) sys.exit(1) importer = IImporter(_importer_defs[importer_name].importer_class()) if options.near: geo_filter_parts = [int(s.strip()) for s in options.near.split(',')] importer = GeoFilter(importer=importer, latitude=geo_filter_parts[0], longitude=geo_filter_parts[2], radius=geo_filter_parts[2]) if filenames: for filename in filenames: with open(filename, 'r') as open_file: _add_file_wrapper(importer, filename, open_file) else: _add_file_wrapper(importer, "-", sys.stdin) records = [] def add_record(record): records.append(normalize_record(record)) importer.create_database(add_record, warning_callback=_general_warning_callback) write_csv_file(sys.stdout, records)
def test_geo_filter_exclude_no(self): filt = GeoFilter(StubImporter([ { 'label': 'none', 'location': None }, { 'label': 'center', 'location': [30, 60] }, { 'label': 'offcenter', 'location': [30.2, 60.2] }, { 'label': 'justoutside', 'location': [30.6, 59.4] }, { 'label': 'distant', 'location': [60, 60] }, ]), latitude=30, longitude=60, radius=50e3, include_no_location=False) self.assertEqual([r[u'label'] for r in run_importer(filt, '')], ['center', 'offcenter'])
def test_geo_filter_include_no(self): filt = GeoFilter( StubImporter([ {'label': 'none', 'location': None}, {'label': 'center', 'location': [30, 60]}, ]), latitude=30, longitude=60, radius=10, include_no_location=True) self.assertEqual( [r[u'label'] for r in run_importer(filt, '')], ['none', 'center'])