Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New maxmind download #1600

Merged
merged 3 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/maxmind_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module MaxmindDatabase
extend self

def download(package, dir = "tmp")
filepath = File.expand_path(File.join(dir, archive_filename(package)))
filepath = File.expand_path(File.join(dir, "#{archive_edition(package)}.zip"))
open(filepath, 'wb') do |file|
uri = URI.parse(archive_url(package))
uri = URI.parse(base_url(package))
Net::HTTP.start(uri.host, uri.port) do |http|
http.request_get(uri.path) do |resp|
# TODO: show progress
Expand Down Expand Up @@ -94,16 +94,16 @@ def archive_url(package)
base_url + archive_url_path(package)
end

def archive_url_path(package)
def archive_edition(package)
{
geolite_country_csv: "GeoLite2-Country-CSV.zip",
geolite_city_csv: "GeoLite2-City-CSV.zip",
geolite_asn_csv: "GeoLite2-ASN-CSV.zip"
geolite_country_csv: "GeoLite2-Country-CSV",
geolite_city_csv: "GeoLite2-City-CSV",
geolite_asn_csv: "GeoLite2-ASN-CSV"
}[package]
end

def base_url
"http://geolite.maxmind.com/download/geoip/database/"
def base_url(edition)
"https://download.maxmind.com/app/geoip_download?edition_id=#{edition}&license_key=#{ENV['LICENSE_KEY']}&suffix=zip"
end
end
end
2 changes: 1 addition & 1 deletion lib/tasks/maxmind.rake
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module MaxmindTask
end
require 'fileutils'
p = "geolite_#{package}_csv".intern
archive_filename = Geocoder::MaxmindDatabase.archive_filename(p)
archive_filename = "#{Geocoder::MaxmindDatabase.archive_edition(p)}.zip"
Zip::File.open(File.join(options[:dir], archive_filename)).each do |entry|
filepath = File.join(options[:dir], entry.name)
if File.exist? filepath
Expand Down