]> WPIA git - gigi.git/blob - util/club/wpia/gigi/util/HighFinancialValueFetcherUmbrella.java
40662e3bf80eb21f8afde718f89fa6a89d50f579
[gigi.git] / util / club / wpia / gigi / util / HighFinancialValueFetcherUmbrella.java
1 package club.wpia.gigi.util;
2
3 import java.io.File;
4 import java.io.PrintWriter;
5 import java.util.HashSet;
6
7 public class HighFinancialValueFetcherUmbrella extends HighFinancialValueFetcher {
8
9     public HighFinancialValueFetcherUmbrella(File f, int max) {
10         super(f, max, "https://s3-us-west-1.amazonaws.com/umbrella-static/top-1m.csv.zip");
11     }
12
13     private HashSet<String> printed = new HashSet<>();
14
15     @Override
16     public void handle(String line, PrintWriter fos) {
17         String[] parts = line.split(",");
18
19         // Assert that the value before the "," is an integer
20         try {
21             if (Integer.parseInt(parts[0]) < 1) {
22                 throw new NumberFormatException("We expect a number greater then zero for the first column.");
23             }
24         } catch (NumberFormatException nfe) {
25             // Bail on lines with invalid first field
26             throw new Error("Invalid format of first column.", nfe);
27         }
28
29         String registrablePart = PublicSuffixes.getInstance().getRegistrablePart(parts[1]);
30         if (registrablePart != null && printed.add(registrablePart)) {
31             emit(fos, registrablePart);
32             System.out.println(registrablePart);
33         }
34
35     }
36
37 }