Skip to content

Instantly share code, notes, and snippets.

@railslove
Created March 27, 2010 11:33
Show Gist options
  • Save railslove/345964 to your computer and use it in GitHub Desktop.
Save railslove/345964 to your computer and use it in GitHub Desktop.
require 'rest_client'
namespace :bankcodes do
desc "Import bankcodes from banklz.net"
task :import => :environment do
total_pages = JSON.parse(RestClient.get("http://banklz.net/bankcodes.json", :timeout => 30))["total_pages"]
bankcodes = []
1.upto(total_pages) do |page|
bankcodes.concat(JSON.parse(RestClient.get("http://banklz.net/bankcodes.json?page=#{page}", :timeout => 30))["bankcodes"])
end
bankcodes.each do |bankcode|
Bankcode.create(:code => bankcode["bankcode"]["code"], :description => bankcode["bankcode"]["description"], :city => bankcode["bankcode"]["city"], :bank_name => bankcode["bankcode"]["bank_name"], :bic => bankcode["bankcode"]["bic"], :property => bankcode["bankcode"]["property"])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment