Skip to content

Commit 9d04d7b

Browse files
committed
Use new 2020 counties list for us_counties
1 parent f6f257f commit 9d04d7b

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ help:
55
@echo "clean-build - remove build artifacts"
66
@echo "clean-py - remove Python file artifacts"
77
@echo "clean-test - remove test and coverage artifacts"
8+
@echo "clean-data - remove all downloaded files in data/"
89

10+
make_data:
11+
mkdir data
912

1013
data/cities500.txt:
1114
curl -o data/cities500.zip http://download.geonames.org/export/dump/cities500.zip
@@ -31,9 +34,9 @@ data/countryInfo.txt:
3134
curl -o data/countryInfo.txt http://download.geonames.org/export/dump/countryInfo.txt
3235

3336
data/us_counties.txt:
34-
curl -o data/us_counties.txt https://www2.census.gov/geo/docs/reference/codes/files/national_county.txt
37+
curl -o data/us_counties.txt https://www2.census.gov/geo/docs/reference/codes2020/national_county2020.txt
3538

36-
dl: data/cities500.txt data/cities1000.txt data/cities5000.txt data/cities15000.txt data/countryInfo.txt data/us_counties.txt
39+
dl: make_data data/cities500.txt data/cities1000.txt data/cities5000.txt data/cities15000.txt data/countryInfo.txt data/us_counties.txt
3740

3841
json:
3942
'./bin/continents.py'
@@ -42,7 +45,10 @@ json:
4245
'./bin/us_counties.py'
4346
mv data/*.json geonamescache/data/
4447

45-
clean: clean-build clean-py clean-test
48+
clean: clean-build clean-py clean-test clean-data
49+
50+
clean-data:
51+
rm -fr data/
4652

4753
clean-build:
4854
rm -fr build/

bin/us_counties.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77

88
reader = csv.reader(p_data.joinpath('us_counties.txt').open())
99

10-
counties = [{'fips': line[1] + line[2], 'name': line[3], 'state': line[0]} for line in reader]
10+
state_name_idx = 0
11+
state_fips_idx = 1
12+
county_fips_idx = 2
13+
county_name_idx = 4
14+
15+
counties = []
16+
for line in reader:
17+
current_line = line[0].split("|")
18+
counties.append(
19+
{
20+
'fips': current_line[state_fips_idx] + current_line[county_fips_idx],
21+
'name': current_line[county_name_idx],
22+
'state': current_line[state_name_idx]
23+
}
24+
)
1125

1226
p_data.joinpath('us_counties.json').write_text(json.dumps(counties))

0 commit comments

Comments
 (0)