From 92550c7649bc86692b3b9951233bb92d2a9900ff Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 23 Jan 2015 15:21:58 +0100 Subject: Add task to fetch postcodes from Bring. --- Rakefile | 2 ++ lib/tasks/norwegian-postcodes.rake | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/Rakefile b/Rakefile index f8af56e..13a7fc7 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +load 'lib/tasks/norwegian-postcodes.rake' + desc "Run unit tests" task "test" do sh 'ruby -Itest/ test/*.rb' diff --git a/lib/tasks/norwegian-postcodes.rake b/lib/tasks/norwegian-postcodes.rake index e69de29..6ec53b7 100644 --- a/lib/tasks/norwegian-postcodes.rake +++ b/lib/tasks/norwegian-postcodes.rake @@ -0,0 +1,13 @@ +require 'uri' +require 'open-uri' + +namespace :postcodes do + desc "Fetch postcode database from Bring" + task :fetch, [:data_path] do |t, args| + args.with_defaults(:data_path => 'data') + uri = URI.parse('http://www.bring.no/hele-bring/forside/_attachment/159761') + filename = File.join(args.data_path, 'Postnummerregister_ansi.txt') + puts "Downloading postcodes to: #{filename}..." + IO.write(filename, uri.read) + end +end -- cgit v1.2.3