Skip to content
Browse files

Initial Commit

  • Loading branch information...
0 parents commit d6b4f287dd451656f7537390730a5cb50c946063 @davglass committed Oct 12, 2011
Showing with 66 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +5 −0 Makefile
  3. +1 −0 lib/codes.js
  4. +29 −0 scripts/fetch.sh
  5. +29 −0 scripts/process.js
2 .gitignore
@@ -0,0 +1,2 @@
+scripts/zips.csv
+scripts/zips.csv.gz
5 Makefile
@@ -0,0 +1,5 @@
+all:
+
+
+zips:
+ ./scripts/fetch.sh
1 lib/codes.js
1 addition, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
29 scripts/fetch.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+cd "$(dirname "$0")"
+
+echo "Fetching zipscodes CSV File"
+
+if [ -f ./zips.csv.gz ]; then
+ rm ./zips.csv.gz
+fi
+
+if [ -f ./zips.csv ]; then
+ rm ./zips.csv
+fi
+
+wget -nv "http://sourceforge.net/projects/zips/files/zips/zips.csv.gz/zips.csv.gz/download"
+
+wait
+
+echo "Unzipping CSV file"
+gzip -d ./zips.csv.gz
+wait
+
+echo "Processing CSV file."
+
+./process.js
+
+wait
+
+echo "Build Complete"
29 scripts/process.js
@@ -0,0 +1,29 @@
+#!/usr/bin/env node
+
+var fs = require('fs'),
+ path = require('path'),
+ zips = {}, str,
+ data = fs.readFileSync('./zips.csv', 'utf8').split('\n');
+
+data.shift();
+
+
+data.forEach(function(line) {
+ line = line.replace(/ /g, '').replace(/"/g, '').split(',');
+ if (line.length > 1) {
+ var o = {};
+
+ o.state = line.pop();
+ o.city = line.pop();
+ o.longitude = line.pop();
+ o.latitude = line.pop();
+ o.abbr = line.pop();
+ o.zip = line.pop();
+
+ zips[o.zip] = o;
+ }
+});
+
+str = 'exports.zips = ' + JSON.stringify(zips) + ';\n';
+
+fs.writeFileSync(path.join('../', 'lib', 'codes.js'), str, 'utf8');

0 comments on commit d6b4f28

Please sign in to comment.
Something went wrong with that request. Please try again.