Rss

ruby CSV Zipcode list parser

Problem: Zip code data file has city, state and zip but also has “acceptable cities”.
We only need City, State and Zip. City being all acceptable cities.

solution: Ruby script to recreate the list with only the needed data.


#!/usr/bin/env ruby
require 'csv'

# place holder for columns
# just to make it more readable
zip = 0
city = 2
citys = 3
state = 5

#empty arrays
zips = []
cities = []

subcity = ""

#Read the CSV file and populate a column array for each row
CSV.foreach(File.path("zip.csv")) do |col|

#get our zip column and add a row to our new array
zips << [col[zip].strip.upcase + "," + col[city].strip.upcase + "," + col[state].strip.upcase]

#check for citys column to see if alternate cities share the same zip code
#if they do share we need to split on comma
mycitys = col[citys]
if mycitys.nil?
#skip
else
if mycitys.include?(",")
#the Citys column has a comma, split
if col[citys] == "" || col[citys].nil?
#do nothing
else
subcity = col[citys].split(',')
if subcity.nil?
#Do nothing
else
#Add each alternate city to the zips array
subcity.each do |mycity|
#puts "here:" + col.to_s
zips << [col[zip].strip.upcase + "," + mycity.strip.upcase + "," + col[state].strip.upcase ]
end
end
end
else
#check for blank
if col[citys].nil?
#do nothing
else
#check for blank
mycity = col[citys].gsub('"',"")
if mycity.length > 0
#not blank, add single alternate city to array
zips << [col[zip].strip.upcase + "," + col[citys].strip.upcase + "," + col[state].strip.upcase ]
end
end
end
end
end

#output the new array
zips.each do |col|
puts col
end

Amateur Extra Class license

Saturday March 8th I went to the Salvation Army EDS Training Facility and took an exam that was hosted by the Indianapolis Radio Club-W9JP.

The test took about 30 minutes to complete and another 15 minutes for the results and certification.

About 9 people were at the event to test. Many were younger than I am. (37).

I was told I had passed my Extra license exam and that they had no more tests for me to take.

What a great group of guys and I enjoyed the experience.