<commit_before># FindTimezoneByIp-plugin

class FindLocationByIp
  cattr_accessor :system_dir
  @@system_dir = File.join(RAILS_ROOT, 'public/system')

  attr_accessor :country_code, :country, :city, :latitude, :longtitude, :timezone
  
  def initialize(ip)
    @loc = {}
    geoip_file = File.join(@@system_dir, 'GeoLiteCity.dat')
    @loc[:geoip] = GeoIP.new(geoip_file).city(ip)
    if @loc[:geoip][7] == ""
      # try hostip if maxmind not found
      @loc[:hostip] = query_hostip(ip)
      @country_code = @loc[:hostip]['country_abbrev']
      @country = @loc[:hostip]['country_name'].titleize
      @city = @loc[:hostip]['name']
      if @loc[:hostip]['ip_location'].present?
        # if ip location found
        @latitude, @longtitude = @loc[:hostip]['ip_location']['point_property']['point']['coordinates'].split(',').reverse.map(&:to_f)
      end
    else
      @country_code = @loc[:geoip][2]
      @country = @loc[:geoip][4]
      @city = @loc[:geoip][7]
      @latitude, @longtitude = @loc[:geoip][9], @loc[:geoip][10]
    end
    begin
      tz = Geonames::WebService.timezone @latitude, @longtitude
      @timezone = tz.timezone_id
    rescue Timeout::Error
      #rescue any errors with web services
    end
  end

  private
    def query_hostip(ip)
      require 'open-uri'
      query = open('http://api.hostip.info/?position=true&ip='+ip)
      Hash.from_xml(query)['hostip_lookup_result_set']['feature_member']['hostip']
    end

end<commit_msg>- fix Hash code for Rails 2.3.3<commit_after># FindTimezoneByIp-plugin

class FindLocationByIp
  cattr_accessor :system_dir
  @@system_dir = File.join(RAILS_ROOT, 'public/system')

  attr_accessor :country_code, :country, :city, :latitude, :longtitude, :timezone
  
  def initialize(ip)
    @loc = {}
    geoip_file = File.join(@@system_dir, 'GeoLiteCity.dat')
    @loc[:geoip] = GeoIP.new(geoip_file).city(ip)
    if @loc[:geoip][7] == ""
      # try hostip if maxmind not found
      @loc[:hostip] = query_hostip(ip)
      @country_code = @loc[:hostip]['countryAbbrev']
      @country = @loc[:hostip]['countryName'].titleize
      @city = @loc[:hostip]['name']
      if @loc[:hostip]['ipLocation'].present?
        # if ip location found
        @latitude, @longtitude = @loc[:hostip]['ipLocation']['PointProperty']['Point']['coordinates'].split(',').reverse.map(&:to_f)
      end
    else
      @country_code = @loc[:geoip][2]
      @country = @loc[:geoip][4]
      @city = @loc[:geoip][7]
      @latitude, @longtitude = @loc[:geoip][9], @loc[:geoip][10]
    end
    begin
      tz = Geonames::WebService.timezone @latitude, @longtitude
      @timezone = tz.timezone_id
    rescue Timeout::Error
      #rescue any errors with web services
    end
  end

  private
    def query_hostip(ip)
      require 'open-uri'
      query = open('http://api.hostip.info/?position=true&ip='+ip)
      raise StandardError, Hash.from_xml(query)['HostipLookupResultSet']['featureMember']['Hostip'].inspect
    end

end
{'fraction_non_alphanumeric': 0.1632996632996633, 'fraction_numerical': 0.005723905723905724, 'mean_word_length': 3.678740157480315, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6581969', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1036, 'n_words': 185}