Sha256: 82b5c5ddc79c9120b5f8bbb3bb8366729dbb65b81f00860f8050ef67058aa7b8

Contents?: true

Size: 874 Bytes

Versions: 4

Compression:

Stored size: 874 Bytes

Contents

# frozen_string_literal: true

require "csv"
require "net/http"
require "tempfile"
require "uri"

namespace :cities do
  desc "Import cities from Istat remote CSV"
  task :import do
    tempfile = Tempfile.new
    tempfile.write Net::HTTP.get(
      URI("https://raw.githubusercontent.com/italia/anpr/master/src/archivi/ANPR_archivio_comuni.csv")
    )

    output_string = CSV.generate do |csv|
      csv << %w[code province name created_on deleted_on]

      CSV.foreach(tempfile.path, encoding: "bom|utf-8", headers: true) do |row|
        csv << [
          row["CODCATASTALE"],
          row["SIGLAPROVINCIA"],
          row["DENOMINAZIONE_IT"].upcase,
          row["DATAISTITUZIONE"],
          row["DATACESSAZIONE"]
        ]
      end
    end

    File.write("lib/itax_code/data/cities.csv", output_string)
  ensure
    tempfile.close
    tempfile.unlink
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
itax_code-2.0.5 rakelib/cities.rake
itax_code-2.0.3 rakelib/cities.rake
itax_code-2.0.2 rakelib/cities.rake
itax_code-2.0.1 rakelib/cities.rake