Esempio n. 1
0
    def handle(self, *args, **options):
        output_filename = options['output_filename']
        logger.info('geocoding zipcodes to %s', output_filename)

        if options['continue_file']:
            mode = 'a'
            zipcodes = GeocodedZipCodeCsv.read(output_filename)
            start = int(max(zipcodes.keys())) + 1
        else:
            mode = 'w'
            start = 0

        logger.info('starting geocoding at %s', start)
        zipcodes = BulkZipCodeGeocoder().geocode_zipcodes(start=start)

        with open(output_filename, mode) as f:
            GeocodedZipCodeCsv.write(f, zipcodes)
 def test_chunker_less_than_one_chunk(self):
     self.assertEqual(
         list(BulkZipCodeGeocoder.chunker([1, 2], 3)),
         [(1, 2)]
     )
 def test_chunker_empty_list(self):
     self.assertEqual(
         list(BulkZipCodeGeocoder.chunker([], 3)),
         []
     )
 def test_generate_possible_zipcodes_partial(self):
     zipcodes = list(BulkZipCodeGeocoder.generate_possible_zipcodes(1234))
     self.assertEqual(len(zipcodes), 98766)
     self.assertEqual(zipcodes[0], '01234')
     self.assertEqual(zipcodes[-1], '99999')
 def test_generate_possible_zipcodes(self):
     zipcodes = list(BulkZipCodeGeocoder.generate_possible_zipcodes())
     self.assertEqual(len(zipcodes), 100000)
     self.assertEqual(zipcodes[1234], '01234')
     self.assertEqual(zipcodes[98765], '98765')
 def test_chunker_elements_do_not_fit_exactly_into_chunks(self):
     self.assertEqual(
         list(BulkZipCodeGeocoder.chunker([1, 2, 3, 4, 5], 3)),
         [(1, 2, 3), (4, 5)]
     )