Skip to content

Commit 8fc7fde

Browse files
Update README
1 parent 4c1577f commit 8fc7fde

3 files changed

Lines changed: 69 additions & 55 deletions

File tree

CHANGELOG

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,33 @@
1010
* Add a ‘name’ index on states table
1111
* Add a switch to generate individual .csv files [--generate-files]
1212
* 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)

README.md

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,70 @@
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+
## History
66

7-
In 2017 we began using [GeoNames](http://www.geonames.org) data, which is licensed under Creative Commons:
7+
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.
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 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.
10+
11+
In 2018 we refactored the project and made it into a Ruby gem with a command-line executable for automating this process.
1012

1113
## What's Included
1214

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.
15+
* 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.
1416

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

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

1921
## Usage
2022

23+
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:
24+
2125
```bash
22-
$ git clone https://github.com/midwire/free_zipcode_data
23-
$ cd free_zipcode_data
24-
$ bundle install
26+
$ gem install free_zipcode_data
2527
```
2628

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...
29+
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...
30+
31+
### Command Line Options
32+
2833
```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
34+
Options:
35+
-w, --work-dir=<s> REQUIRED: Specify your work/build directory, where the SQLite and .csv files will be built
36+
-f, --country=<s> Specify the country code for processing, or all countries if not specified
37+
-g, --generate-files Generate CSV files: [counties.csv, states.csv, countries.csv, zipcodes.csv]
38+
-o, --country-tablename=<s> Specify the name for the `countries` table (default: countries)
39+
-s, --state-tablename=<s> Specify the name for the `states` table (default: states)
40+
-u, --county-tablename=<s> Specify the name for the `counties` table (default: counties)
41+
-z, --zipcode-tablename=<s> Specify the name for the `zipcodes` table (default: zipcodes)
42+
-c, --clobber Overwrite existing files
43+
-d, --dry-run Do not actually move or copy files
44+
-v, --verbose Be verbose with output
45+
-h, --help Show this message
3446
```
3547
48+
### Examples
49+
50+
**Download and process all US zipcodes**:
51+
3652
```bash
37-
# build the .csv files
38-
$ rake data:build[country]
39-
# rake data:build - ALL countries
53+
$ free_zipcode_data --work-dir /tmp/work_dir --country US --generate-files
4054
```
4155
56+
**Download and process zipcodes for all available countries**:
57+
4258
```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
59+
$ free_zipcode_data --work-dir /tmp/work_dir --generate-files
4660
```
4761
4862
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.
4963
5064
## SQLite3 Database
5165
52-
The rake task `rake data:populate_db[country]` will create an SQLite3 database with the following tables, and populate each one:
66+
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.
67+
68+
By default the tables will be named as follows. To override the table names see the command line options above.
5369
5470
```sql
5571
create table countries (
@@ -79,7 +95,6 @@ create table zipcodes (
7995
id integer not null primary key,
8096
code varchar(10) not null,
8197
state_id integer,
82-
county_id integer,
8398
city varchar(255),
8499
area_code varchar(3),
85100
lat float,
@@ -90,41 +105,10 @@ create table zipcodes (
90105
91106
Both `lat` and `lon`, geocodes, are populated for each zipcode record.
92107
93-
## Development
94-
95-
If you want to run the specs or do development work, set `GEM_ENV='development'`
96-
97108
## Data License
98109
99110
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 />
100111
<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>
101112
102-
## Errata
103-
104-
### 10/28/2017:
105-
106-
* Removed old .csv files
107-
* Add template files (CODE_OF_CONDUCT.md, CONTRIBUTING.md, ISSUE_TEMPLATE.md, LICENSE.md, PULL_REQUEST_TEMPLATE.md)
108-
* Use new data provider - [GeoNames](http://www.geonames.org)
109-
* Test USA
110-
* Started to test `allCountries.zip` but it takes too long. Let me know if there are any bugs.
111-
* Create `country_lookup_table.yml` for country code lookups
112-
113-
### 05/04/2011:
114-
115-
* Removed un-assigned zipcodes, which were not valid for today
116-
* Added a Rakefile and some rake tasks to facilitate building a SQLite relational database for the three tables (states, counties, zipcodes)
117-
* Zipcodes without an associated county == 0
118-
* Counties without a zipcode == 1 (PISCATAGUIS, Maine)
119-
120-
### 01/24/2011:
121-
122-
* 670 orphaned zipcodes without an associated county
123-
* 1 county without any zipcodes (PISCATAGUIS, Maine)
124-
125-
### 01/13/2011:
126-
127-
At last check there were ...
128113
129-
* 897 orphaned zipcodes without an associated county
130-
* 1 county without any zipcodes (PISCATAGUIS, Maine)
114+
See [CHANGELOG](CHANGELOG) for history and errata.

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
ENV['GEM_ENV'] = 'test'
3+
ENV['APP_ENV'] = 'test'
44

55
require 'pry'
66

0 commit comments

Comments
 (0)