Skip to content

Commit 1a18feb

Browse files
authored
Merge pull request #11 from midwire/develop
Release gem version 1.0.1
2 parents 6599105 + af46d3f commit 1a18feb

30 files changed

+1221
-419
lines changed

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
ZIP_CODES.txt
2-
zip_codes.zip
3-
zip_dump.csv
4-
zip_codes.db
51
/.bundle
62
/free_zipcode_data.sqlite3
73
/data
84
/build
5+
/stubs
6+
/vendor/bundle/
7+
/pkg

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--require spec_helper

.rubocop.yml

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
AllCops:
2+
TargetRubyVersion: 2.3
3+
24
# Include gemspec and Rakefile
35
Include:
46
- '**/*.gemspec'
@@ -15,6 +17,7 @@ AllCops:
1517
Exclude:
1618
- 'vendor/**/*'
1719
- 'stubs/**/*'
20+
- 'spec/support/shared_contexts/*'
1821

1922
# Checks formatting of special comments
2023
CommentAnnotation:
@@ -28,6 +31,9 @@ CommentAnnotation:
2831
########################################
2932
# Style Cops
3033

34+
Style/ClassVars:
35+
Enabled: false
36+
3137
Style/Documentation:
3238
Enabled: false
3339

@@ -49,32 +55,16 @@ Style/RaiseArgs:
4955
Style/DoubleNegation:
5056
Enabled: false
5157

52-
Style/SignalException:
53-
EnforcedStyle: semantic
54-
55-
Style/ClassAndModuleChildren:
56-
Enabled: false
57-
58-
Style/MultilineMethodCallIndentation:
59-
EnforcedStyle: indented
60-
IndentationWidth: 4
61-
62-
Style/CaseIndentation:
63-
Enabled: false
64-
65-
Style/TrivialAccessors:
66-
Enabled: false
67-
68-
Style/NumericLiterals:
58+
Style/PerlBackrefs:
6959
Enabled: false
7060

7161
########################################
7262
# Lint Cops
7363

7464
Lint/Eval:
75-
Enabled: true
65+
Enabled: false
7666

77-
Lint/AssignmentInCondition:
67+
Lint/HandleExceptions:
7868
Enabled: false
7969

8070
########################################
@@ -85,7 +75,14 @@ Metrics/LineLength:
8575

8676
Metrics/MethodLength:
8777
CountComments: false # count full line comments?
88-
Max: 20
78+
Max: 30
8979

9080
Metrics/ClassLength:
9181
Max: 120
82+
83+
Metrics/AbcSize:
84+
Enabled: false
85+
86+
# rubocop:disable Metrics/AbcSize
87+
# rubocop:disable Metrics/MethodLength
88+
# rubocop:disable Metrics/BlockLength

CHANGELOG

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
*1.0.1* (April 23, 2018)
2+
3+
* Made it a gem with a command line executable bin/free_zipcode_data
4+
* Use Kiba for ETL
5+
* Support user switches for various options including custom table names and generating .csv files
6+
* Use in-memory SQLite database to create the tables, then save it as a file on disk
7+
* Separate concerns for each table
8+
* Add a progressbar with ETA
9+
* Fix a bug when looking up state_id
10+
* Add a ‘name’ index on states table
11+
* Add a switch to generate individual .csv files [--generate-files]
12+
* Add a switch to overwrite [--clobber] downloaded and generated .csv files
13+
14+
### Previous History
15+
16+
### 10/28/2017:
17+
18+
* Removed old .csv files
19+
* Add template files (CODE_OF_CONDUCT.md, CONTRIBUTING.md, ISSUE_TEMPLATE.md, LICENSE.md, PULL_REQUEST_TEMPLATE.md)
20+
* Use new data provider - [GeoNames](http://www.geonames.org)
21+
* Test USA
22+
* Started to test `allCountries.zip` but it takes too long. Let me know if there are any bugs.
23+
* Create `country_lookup_table.yml` for country code lookups
24+
25+
### 05/04/2011:
26+
27+
* Removed un-assigned zipcodes, which were not valid for today
28+
* Added a Rakefile and some rake tasks to facilitate building a SQLite relational database for the three tables (states, counties, zipcodes)
29+
* Zipcodes without an associated county == 0
30+
* Counties without a zipcode == 1 (PISCATAGUIS, Maine)
31+
32+
### 01/24/2011:
33+
34+
* 670 orphaned zipcodes without an associated county
35+
* 1 county without any zipcodes (PISCATAGUIS, Maine)
36+
37+
### 01/13/2011:
38+
39+
At last check there were ...
40+
41+
* 897 orphaned zipcodes without an associated county
42+
* 1 county without any zipcodes (PISCATAGUIS, Maine)

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## How to contribute to jsonapi_rspec
1+
## How to contribute to free_zipcode_data
22

33
#### **Did you find a bug?**
44

Gemfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
source 'http://rubygems.org'
1+
# frozen_string_literal: true
22

3-
gem 'midwire_common'
4-
gem 'pry-nav'
5-
gem 'rake'
6-
gem 'rubyzip', '~> 1.2.1'
7-
gem 'sqlite3'
3+
source 'https://rubygems.org'
4+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5+
6+
gemspec

Gemfile.lock

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,82 @@
1+
PATH
2+
remote: .
3+
specs:
4+
free_zipcode_data (1.0.1)
5+
colored (~> 1.2)
6+
kiba (~> 2.0)
7+
ruby-progressbar (~> 1.9)
8+
rubyzip (~> 1.2)
9+
sqlite3 (~> 1.3)
10+
trollop (~> 2.1)
11+
112
GEM
2-
remote: http://rubygems.org/
13+
remote: https://rubygems.org/
314
specs:
15+
ast (2.4.0)
416
coderay (1.1.2)
17+
colored (1.2)
18+
diff-lcs (1.3)
19+
docile (1.3.0)
20+
json (2.1.0)
21+
kiba (2.0.0)
522
method_source (0.8.2)
6-
midwire_common (0.1.16)
7-
thor (~> 0.19)
23+
parallel (1.12.1)
24+
parser (2.5.1.0)
25+
ast (~> 2.4.0)
26+
powerpack (0.1.1)
827
pry (0.10.4)
928
coderay (~> 1.1.0)
1029
method_source (~> 0.8.1)
1130
slop (~> 3.4)
1231
pry-nav (0.2.4)
1332
pry (>= 0.9.10, < 0.11.0)
33+
rainbow (3.0.0)
1434
rake (12.2.1)
35+
rspec (3.7.0)
36+
rspec-core (~> 3.7.0)
37+
rspec-expectations (~> 3.7.0)
38+
rspec-mocks (~> 3.7.0)
39+
rspec-core (3.7.1)
40+
rspec-support (~> 3.7.0)
41+
rspec-expectations (3.7.0)
42+
diff-lcs (>= 1.2.0, < 2.0)
43+
rspec-support (~> 3.7.0)
44+
rspec-mocks (3.7.0)
45+
diff-lcs (>= 1.2.0, < 2.0)
46+
rspec-support (~> 3.7.0)
47+
rspec-support (3.7.1)
48+
rubocop (0.55.0)
49+
parallel (~> 1.10)
50+
parser (>= 2.5)
51+
powerpack (~> 0.1)
52+
rainbow (>= 2.2.2, < 4.0)
53+
ruby-progressbar (~> 1.7)
54+
unicode-display_width (~> 1.0, >= 1.0.1)
55+
ruby-prof (0.17.0)
56+
ruby-progressbar (1.9.0)
1557
rubyzip (1.2.1)
58+
simplecov (0.16.1)
59+
docile (~> 1.1)
60+
json (>= 1.8, < 3)
61+
simplecov-html (~> 0.10.0)
62+
simplecov-html (0.10.2)
1663
slop (3.6.0)
17-
sqlite3 (1.3.11)
18-
thor (0.19.1)
64+
sqlite3 (1.3.13)
65+
trollop (2.1.2)
66+
unicode-display_width (1.3.2)
1967

2068
PLATFORMS
2169
ruby
2270

2371
DEPENDENCIES
24-
midwire_common
25-
pry-nav
26-
rake
27-
rubyzip (~> 1.2.1)
28-
sqlite3
72+
bundler (~> 1.16)
73+
free_zipcode_data!
74+
pry-nav (~> 0.2)
75+
rake (~> 12.0)
76+
rspec (~> 3.7)
77+
rubocop (~> 0.55)
78+
ruby-prof (~> 0.17)
79+
simplecov (~> 0.16)
2980

3081
BUNDLED WITH
31-
1.15.4
82+
1.16.1

README.md

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,72 @@
22

33
Zipcode data is free from the various governments around the world. Yet so many organizations, reputable or not, want to charge money for it.
44

5-
We originally pulled down all the US census data we could find, parsed it and exported it into .csv files.
5+
This project is an automated solution for retrieving and collating US and worldwide zipcode data.
66

7-
In 2017 we began using [GeoNames](http://www.geonames.org) data, which is licensed under Creative Commons:
7+
## History
88

9-
We thank [GeoNames](http://www.geonames.org) for sharing, and urge you to [visit their site](http://www.geonames.org) and support their work.
9+
In 2011, we originally pulled down all the US census data we could find, parsed it and exported it into 3 .csv files. Later, we wrote 3 rake tasks to automate this process.
10+
11+
In 2017 we began using [GeoNames](http://www.geonames.org) data, which is licensed under Creative Commons. We are grateful to [GeoNames](http://www.geonames.org) for sharing, and urge you to [visit their site](http://www.geonames.org) and support their work.
12+
13+
In 2018 we refactored the project and made it into a Ruby gem with a command-line executable for automating this process.
1014

1115
## What's Included
1216

13-
There are three rake tasks which automatically download the latest zipcode data from the country that you specify. Not all countries are accounted for. Please check [GeoNames](http://download.geonames.org/export/zip/) to see a list of supported country zip files.
17+
* An executable: `free_zipcode_data` - which automates the process of downloading and process the zipcode data from GeoNames. Not all countries are accounted for. Please check [GeoNames](http://download.geonames.org/export/zip/) to see a list of supported country zip files.
1418

15-
Each zipcode is correlated with estimated or zip-centroid, latitude and longitude coordinates. Where applicable, county/province, state and community are also correlated.
19+
Each zipcode is correlated with estimated or zip-centroid, latitude and longitude coordinates. Where applicable, country, county/province, state and community are also correlated.
1620

1721
See the GeoNames [readme.txt](http://download.geonames.org/export/zip/readme.txt) file for more information.
1822

1923
## Usage
2024

25+
First, you need to install Ruby and Rubygems. Though that is not a difficult task, it is beyond the scope of this README. A search engine of your choice will help discover how to do this. Once you have done that:
26+
2127
```bash
22-
$ git clone https://github.com/midwire/free_zipcode_data
23-
$ cd free_zipcode_data
24-
$ bundle install
28+
$ gem install free_zipcode_data
2529
```
2630

27-
Determine the countries you want to use at [GeoNames](http://download.geonames.org/export/zip/), or just use the rake task without any `country` argument to get zipcode data for all countries...
31+
Determine the 2-letter country codes for the countries you want to use at [GeoNames](http://download.geonames.org/export/zip/), or don't specify a country to get all zipcodes for all available countries...
32+
33+
### Command Line Options
34+
2835
```bash
29-
# download will pull down the zipcodes for the specified country
30-
$ rake data:download[country]
31-
# rake data:download[US] - For US-only zipcodes
32-
# rake data:download[GB_full.csv] - All UK data zipcodes:
33-
# rake data:download - ALL zipcodes
36+
Options:
37+
-w, --work-dir=<s> REQUIRED: Specify your work/build directory, where the SQLite and .csv files will be built
38+
-f, --country=<s> Specify the country code for processing, or all countries if not specified
39+
-g, --generate-files Generate CSV files: [counties.csv, states.csv, countries.csv, zipcodes.csv]
40+
-o, --country-tablename=<s> Specify the name for the `countries` table (default: countries)
41+
-s, --state-tablename=<s> Specify the name for the `states` table (default: states)
42+
-u, --county-tablename=<s> Specify the name for the `counties` table (default: counties)
43+
-z, --zipcode-tablename=<s> Specify the name for the `zipcodes` table (default: zipcodes)
44+
-c, --clobber Overwrite existing files
45+
-d, --dry-run Do not actually move or copy files
46+
-v, --verbose Be verbose with output
47+
-h, --help Show this message
3448
```
3549
50+
### Examples
51+
52+
**Download and process all US zipcodes**:
53+
3654
```bash
37-
# build the .csv files
38-
$ rake data:build[country]
39-
# rake data:build - ALL countries
55+
$ free_zipcode_data --work-dir /tmp/work_dir --country US --generate-files
4056
```
4157
58+
**Download and process zipcodes for all available countries**:
59+
4260
```bash
43-
# populate_db will automatically download the zips and build the sqlite3 db
44-
$ rake data:populate_db[country]
45-
# rake data:populate_db - ALL countries - WARNING: takes a long time
61+
$ free_zipcode_data --work-dir /tmp/work_dir --generate-files
4662
```
4763
4864
The rake tasks cascade, from the bottom up. So if you run `rake data:populate_db`, it will automatically call `rake data:build` if the .csv files are missing, which will call `rake data:download` if the .zip files are missing.
4965
5066
## SQLite3 Database
5167
52-
The rake task `rake data:populate_db[country]` will create an SQLite3 database with the following tables, and populate each one:
68+
The executable will generate an SQLite3 database in the specified directory `--work-dir` but it will not generate the `.csv` files by default. Specify `--generate-files` if you want those as well.
69+
70+
By default the tables will be named as follows. To override the table names see the command line options above.
5371
5472
```sql
5573
create table countries (
@@ -79,7 +97,6 @@ create table zipcodes (
7997
id integer not null primary key,
8098
code varchar(10) not null,
8199
state_id integer,
82-
county_id integer,
83100
city varchar(255),
84101
area_code varchar(3),
85102
lat float,
@@ -95,32 +112,4 @@ Both `lat` and `lon`, geocodes, are populated for each zipcode record.
95112
The zipcode data is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>, carried forward from [GeoNames](http://www.geonames.org).<br />
96113
<a rel="license" href="http://creativecommons.org/licenses/by/3.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/3.0/88x31.png" /></a>
97114
98-
## Errata
99-
100-
### 10/28/2017:
101-
102-
* Removed old .csv files
103-
* Add template files (CODE_OF_CONDUCT.md, CONTRIBUTING.md, ISSUE_TEMPLATE.md, LICENSE.md, PULL_REQUEST_TEMPLATE.md)
104-
* Use new data provider - [GeoNames](http://www.geonames.org)
105-
* Test USA
106-
* Started to test `allCountries.zip` but it takes too long. Let me know if there are any bugs.
107-
* Create `country_lookup_table.yml` for country code lookups
108-
109-
### 05/04/2011:
110-
111-
* Removed un-assigned zipcodes, which were not valid for today
112-
* Added a Rakefile and some rake tasks to facilitate building a SQLite relational database for the three tables (states, counties, zipcodes)
113-
* Zipcodes without an associated county == 0
114-
* Counties without a zipcode == 1 (PISCATAGUIS, Maine)
115-
116-
### 01/24/2011:
117-
118-
* 670 orphaned zipcodes without an associated county
119-
* 1 county without any zipcodes (PISCATAGUIS, Maine)
120-
121-
### 01/13/2011:
122-
123-
At last check there were ...
124-
125-
* 897 orphaned zipcodes without an associated county
126-
* 1 county without any zipcodes (PISCATAGUIS, Maine)
115+
See [CHANGELOG](CHANGELOG) for more history and errata.

Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
# frozen_string_literal: true
2+
13
require 'rubygems'
24
require 'bundler/setup'
35

46
require 'rake'
57
Dir['lib/tasks/**/*.rake'].sort.each { |ext| load ext }
8+
9+
# Install rubygem tasks
10+
Bundler::GemHelper.install_tasks

0 commit comments

Comments
 (0)