19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/zip_geo_jp/rake_helper.rb', line 19
def update
DOWNLOAD_URL_SUFFIX.map do |suffix|
download_url = DOWNLOAD_URL_ENDPOINT + suffix
records = (download_url)
Parallel.each(records, in_threads: GOOGLE_MAP_CRAWLING_CONCURRENCY) do |zip_code, pref, city, block|
puts "Item: #{zip_code} #{pref}#{city}#{block}, Worker: #{Parallel.worker_number}"
unless ZipGeoJp::Record[zip_code]
coordinates = coordinates_from_google_map(zip_code)
ZipGeoJp::Record[zip_code] = {
prefecture: pref,
city: city,
block: block,
latitude: coordinates[0],
longitude: coordinates[1],
}
sleep(GOOGLE_MAP_CRAWLING_DURATION)
end
end
end
end
|