3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/geonames_rails/puller.rb', line 3
def pull
@temp_geonames_files = []
target_dir = File.join(Rails.root, 'tmp')
file_names = %w(cities1000.zip admin1CodesASCII.txt countryInfo.txt)
file_names.each do |file_name|
url = "http://download.geonames.org/export/dump/#{file_name}"
remote_file = open(url)
target_file_name = File.join(target_dir, file_name)
File.open target_file_name, 'w' do |f|
f.write(remote_file.read.force_encoding("UTF-8"))
end
remote_file.close
@temp_geonames_files << target_file_name
file_base_name, file_extension = file_name.split('.')
end
end
|