Skip to content

Commit 10c9f3a

Browse files
author
Chris Blackburn
committed
Use new data source, refactor everything.
1 parent ab5228a commit 10c9f3a

20 files changed

Lines changed: 1600 additions & 92664 deletions

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
ZIP_CODES.txt
22
zip_codes.zip
33
zip_dump.csv
4-
zip_codes.db
4+
zip_codes.db
5+
/.bundle
6+
/free_zipcode_data.sqlite3
7+
/data
8+
/build

.rubocop.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
AllCops:
2+
# Include gemspec and Rakefile
3+
Include:
4+
- '**/*.gemspec'
5+
- '**/*.podspec'
6+
- '**/*.jbuilder'
7+
- '**/*.rake'
8+
- '**/Gemfile'
9+
- '**/Rakefile'
10+
- '**/Capfile'
11+
- '**/Guardfile'
12+
- '**/Podfile'
13+
- '**/Thorfile'
14+
- '**/Vagrantfile'
15+
Exclude:
16+
- 'vendor/**/*'
17+
- 'stubs/**/*'
18+
19+
# Checks formatting of special comments
20+
CommentAnnotation:
21+
Keywords:
22+
- TODO
23+
- FIXME
24+
- OPTIMIZE
25+
- HACK
26+
- REVIEW
27+
28+
########################################
29+
# Style Cops
30+
31+
Style/Documentation:
32+
Enabled: false
33+
34+
Style/FileName:
35+
Enabled: false
36+
37+
Style/AlignParameters:
38+
EnforcedStyle: with_fixed_indentation
39+
40+
Style/RegexpLiteral:
41+
Enabled: false
42+
43+
Style/EmptyLinesAroundBlockBody:
44+
Enabled: false
45+
46+
Style/RaiseArgs:
47+
Enabled: false
48+
49+
Style/DoubleNegation:
50+
Enabled: false
51+
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:
69+
Enabled: false
70+
71+
########################################
72+
# Lint Cops
73+
74+
Lint/Eval:
75+
Enabled: true
76+
77+
Lint/AssignmentInCondition:
78+
Enabled: false
79+
80+
########################################
81+
# Metrics Cops
82+
83+
Metrics/LineLength:
84+
Max: 110
85+
86+
Metrics/MethodLength:
87+
CountComments: false # count full line comments?
88+
Max: 20
89+
90+
Metrics/ClassLength:
91+
Max: 120

CODE_OF_CONDUCT.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Free Zipcode Data Code of Conduct
2+
3+
The Free Zipcode Data project strongly values contributors from anywhere, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, physical appearance, body size, race, ethnicity, age, religion, or nationality. As a result, the Free Zipcode Data team has agreed to and enforces this code of conduct in order to provide a harassment-free experience for everyone who participates in the development of Free Zipcode Data.
4+
5+
### Summary
6+
7+
Just Be Nice!!!
8+
9+
Harassment in code and discussion or violation of physical boundaries is completely unacceptable anywhere in the Free Zipcode Data codebase, issue trackers, chat rooms, mailing lists, meetups, and any other events. Violators will be warned and then blocked or banned by the core team at or before the 3rd violation.
10+
11+
### In Detail
12+
13+
Harassment includes offensive verbal comments related to level of experience, gender, gender identity and expression, sexual orientation, disability, physical appearance, body size, race, ethnicity, age, religion, nationality, the use of sexualized language or imagery, deliberate intimidation, stalking, sustained disruption, and unwelcome sexual attention.
14+
15+
Individuals asked to stop any harassing behavior are expected to comply immediately.
16+
17+
Maintainers, including the core team, are also subject to the anti-harassment policy.
18+
19+
If anyone engages in abusive, harassing, or otherwise unacceptable behavior, including maintainers, we may take appropriate action, up to and including warning the offender, deletion of comments, removal from the project’s codebase and communication systems, and escalation to GitHub support.
20+
21+
If you are being harassed, notice that someone else is being harassed, or have any other concerns, please contact [Chris Blackburn](mailto:87a1779b@opayq.com).
22+
23+
We expect everyone to follow these rules anywhere in the Free Zipcode Data codebase, issue trackers, IRC channel, group chat, and mailing lists.
24+
25+
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
26+
27+
Finally, don't forget that it is human to make mistakes! We all do. Let’s work together to help each other, resolve issues, and learn from the mistakes that we will all inevitably make from time to time.
28+
29+
### Thanks
30+
31+
Thanks to the [JSConf Code of Conduct](http://jsconf.com/codeofconduct.html) and [Fedora Code of Conduct](http://fedoraproject.org/code-of-conduct) for inspiration and ideas.
32+
33+
### License
34+
35+
<p class="license" xmlns:dct="http://purl.org/dc/terms/" xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#">
36+
To the extent possible under law, <a rel="dct:publisher" href="https://github.com/midwire/free_zipcode_data">The Free Zipcode Data Team</a> has waived all copyright and related or neighboring rights to the <span property="dct:title">Free Zipcode Data Code of Conduct</span>. This work is published from the <span property="vcard:Country" datatype="dct:ISO3166" content="US" about="https://github.com/midwire/free_zipcode_data">United States.</span>
37+
<br>
38+
<br>
39+
<a rel="license" href="http://creativecommons.org/publicdomain/zero/1.0/">
40+
<img src="http://i.creativecommons.org/p/zero/1.0/88x31.png" style="border-style: none;" alt="CC0">
41+
</a>
42+
</p>

CONTRIBUTING.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## How to contribute to jsonapi_rspec
2+
3+
#### **Did you find a bug?**
4+
5+
* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/midwire/free_zipcode_data/issues).
6+
7+
* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/midwire/free_zipcode_data/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
8+
9+
#### **Did you write a patch that fixes a bug?**
10+
11+
* Open a new GitHub pull request with the patch.
12+
13+
* Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
14+
15+
* Before submitting, please read run [Rubocop](http://batsov.com/rubocop/) on your code. If your PR fails our Rubocop convensions defined in `.rubocop.yml`, it will likely be rejected on those grounds.
16+
17+
* Ensure that you write RSpec tests that cover any new or modified code. PR's without spec coverage will likely be rejected.
18+
19+
#### **Did you fix whitespace, format code, or make a purely cosmetic patch?**
20+
21+
Changes that are cosmetic in nature and do not add anything substantial to the stability, functionality, or testability of Free Zipcode Data will generally not be accepted.
22+
23+
Thanks for any contributions!
24+
25+
--Midwire

Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
source 'http://rubygems.org'
2+
3+
gem 'midwire_common'
4+
gem 'pry-nav'
5+
gem 'rake'
6+
gem 'rubyzip', '~> 1.2.1'
7+
gem 'sqlite3'
8+
gem 'nokogiri'

Gemfile.lock

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
coderay (1.1.2)
5+
method_source (0.8.2)
6+
midwire_common (0.1.16)
7+
thor (~> 0.19)
8+
mini_portile2 (2.3.0)
9+
nokogiri (1.8.1)
10+
mini_portile2 (~> 2.3.0)
11+
pry (0.10.4)
12+
coderay (~> 1.1.0)
13+
method_source (~> 0.8.1)
14+
slop (~> 3.4)
15+
pry-nav (0.2.4)
16+
pry (>= 0.9.10, < 0.11.0)
17+
rake (12.2.1)
18+
rubyzip (1.2.1)
19+
slop (3.6.0)
20+
sqlite3 (1.3.11)
21+
thor (0.19.1)
22+
23+
PLATFORMS
24+
ruby
25+
26+
DEPENDENCIES
27+
midwire_common
28+
nokogiri
29+
pry-nav
30+
rake
31+
rubyzip (~> 1.2.1)
32+
sqlite3
33+
34+
BUNDLED WITH
35+
1.15.4

ISSUE_TEMPLATE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### Expected Behavior
2+
3+
### Actual Behavior
4+
5+
### Steps to reproduce the problem
6+
7+
---
8+
* Current Version:
9+
* Operating System:

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## The MIT License (MIT)
2+
3+
##### Copyright (c) 2017 Midwire Technologies, LLC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
**_THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE._**

PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- [ ] I wrote specs to cover new or modified code in this PR
2+
- [ ] I ran `rake spec` locally and ALL specs pass
3+
4+
Related Issue: # <please-add-issue-number-here>
5+
Description: <please-add-a-comprehensive-description-of-fix/feature>

README.md

Lines changed: 89 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,98 @@
11
# Free Zipcode Data
22

3-
We got sick and tired of trying to find free zipcode data. So we pulled down all the census data we could find, parsed it and exported it into these .csv files.
3+
Zipcode data is free from the various governments around the world. Yet so many organizations, reputable or not, want to charge money for it.
4+
5+
We originally pulled down all the US census data we could find, parsed it and exported it into .csv files.
6+
7+
In 2017 we began using [GeoNames](http://www.geonames.org) data, which is licensed under Creative Commons:
8+
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.
10+
11+
## What's Included
12+
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.
14+
15+
Each zipcode is correlated with estimated or zip-centroid, latitude and longitude coordinates. Where applicable, county/province, state and community are also correlated.
16+
17+
See the GeoNames [readme.txt](http://download.geonames.org/export/zip/readme.txt) file for more information.
18+
19+
## Usage
20+
21+
```bash
22+
$ git clone https://github.com/midwire/free_zipcode_data
23+
$ cd free_zipcode_data
24+
```
25+
26+
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...
27+
```bash
28+
# download will pull down the zipcodes for the specified country
29+
$ rake data:download[country]
30+
# rake data:download[US] - For US-only zipcodes
31+
# rake data:download[GB_full.csv] - All UK data zipcodes:
32+
# rake data:download - ALL zipcodes
33+
```
34+
35+
```bash
36+
# build the .csv files
37+
$ rake data:build[country]
38+
# rake data:build - ALL countries
39+
```
40+
41+
```bash
42+
# populate_db will automatically download the zips and build the .csv files
43+
$ rake data:populate_db[country]
44+
# rake data:populate_db - ALL countries - WARNING: takes a long time
45+
```
46+
47+
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.
48+
49+
## SQLite3 Database
50+
51+
The rake task `rake data:populate_db[country]` will create an SQLite3 database with the following tables, and populate each one:
52+
53+
```sql
54+
create table countries (
55+
id integer not null primary key,
56+
alpha2 varchar(2) not null,
57+
alpha3 varchar(3),
58+
iso varchar(3),
59+
name varchar(255) not null
60+
)
61+
62+
create table states (
63+
id integer not null primary key,
64+
country_id integer not null,
65+
abbr varchar(2) not null,
66+
name varchar(255)
67+
)
68+
69+
create table counties (
70+
id integer not null primary key,
71+
state_id integer,
72+
abbr varchar(255),
73+
name varchar(255),
74+
county_seat varchar(255)
75+
)
76+
77+
create table zipcodes (
78+
id integer not null primary key,
79+
code varchar(10) not null,
80+
state_id integer,
81+
county_id integer,
82+
city varchar(255),
83+
area_code varchar(3),
84+
lat float,
85+
lon float,
86+
accuracy varchar(8)
87+
)
88+
```
489

5-
## CSV Data
6-
7-
### `all_us_counties.csv`
8-
name, state, county_seat
9-
10-
### `all_us_states.csv`
11-
abbr, name
12-
13-
### `all_us_zipcodes.csv`
14-
code, city, state, county, area_code, lat, lon
15-
1690
Both `lat` and `lon`, geocodes, are populated for each zipcode record.
1791

18-
## SQL Data
19-
20-
### `counties_states_zipcodes.sql`
21-
22-
This is a MySQL ready dump of the three tables `counties`, `states` and `zipcodes`. Both structure and data, along with complete and extended INSERTs are included in the dump.
23-
24-
## Updating
92+
## Data License
2593

26-
Please add any missing data, or correct mistakes, and send us a pull request.
94+
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 />
95+
<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>
2796

2897
## Errata
2998

0 commit comments

Comments
 (0)