I would like to update the table of cities every week to reflect changes in cities around the world. I am creating a Rake task for this purpose. If possible, I would like to do this without adding another gem dependency .
The reserved file is a public zipped file at geonames.org/15000cities.zip .
My attempt:
require 'net/http'
require 'zip'
namespace :geocities do
desc "Rake task to fetch Geocities city list every 3 days"
task :fetch do
uri = URI('http://download.geonames.org/export/dump/cities15000.zip')
zipped_folder = Net::HTTP.get(uri)
Zip::File.open(zipped_folder) do |unzipped_folder|
unzipped_folder.each do |file|
Rails.root.join("", "list_of_cities.txt").write(file)
end
end
end
end
Return from rake geocities:fetch
rake aborted!
ArgumentError: string contains null byte
, list_of_cities.txt. , , , db . ( , db, , , .)