Ignore:
Timestamp:
2019-10-24T23:22:30+13:00 (5 years ago)
Author:
ak19
Message:
  1. Better output into possible-product-sites.txt including the overseas country code prefix to help decide whether the site is worth keeping or not. 2. Updated whitelisting and top-sites filters to grab the /mi/ subsections of sites that don't appear to be autotranslated. This is done in preparation for blocking out product sites hereafter
File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/maori-lang-detection/src/org/greenstone/atea/Utility.java

    r33603 r33604  
    5454     * version I'm using: https://github.com/maxmind/geoip-api-java
    5555     * Newer version: https://maxmind.github.io/GeoIP2-java/
     56     *
     57     * @return 2 letter countrycode in uppercase or an exception
    5658     */
     59    public static String getCountryCodeOfDomain(String domainWithProtocol, File geoLiteCityDatFile)
     60    throws Exception
     61    {   
     62    int startIndex = domainWithProtocol.indexOf("//"); // http:// or https:// prefix
     63    startIndex = (startIndex == -1) ? 0 : (startIndex+2); // skip past the protocol's // portion
     64    String domain = domainWithProtocol.substring(startIndex);   
     65   
     66    // pass in the GeoLiteCity.dat file to be able to do the location lookup for domain's IP
     67    LookupService cl = new LookupService(geoLiteCityDatFile, LookupService.GEOIP_MEMORY_CACHE);
     68       
     69    // get IP for domain
     70    InetAddress inetAddress = InetAddress.getByName(domain);
     71    String ipAddress = inetAddress.getHostAddress();
     72   
     73    // get location object for IP
     74    Location location = cl.getLocation(ipAddress);
     75   
     76    if(location == null) {
     77        throw new Exception("@@@@ No location info in DB for: " + domain);
     78    } else {
     79        return location.countryCode;
     80    }
     81   
     82    }
     83   
    5784    public static boolean isDomainInCountry(String domainWithProtocol,
    5885                        String countryCode, File geoLiteCityDatFile)
Note: See TracChangeset for help on using the changeset viewer.