]> WPIA git - gigi.git/blob - util/org/cacert/gigi/util/HighFinancialValueFetcher.java
upd: minor fixup on highFinancialValue code
[gigi.git] / util / org / cacert / gigi / util / HighFinancialValueFetcher.java
1 package org.cacert.gigi.util;
2
3 import java.io.BufferedReader;
4 import java.io.File;
5 import java.io.IOException;
6 import java.io.InputStreamReader;
7 import java.io.PrintWriter;
8 import java.net.URL;
9 import java.util.zip.ZipEntry;
10 import java.util.zip.ZipInputStream;
11
12 public class HighFinancialValueFetcher {
13
14     public static void main(String[] args) throws IOException {
15         int max = 1000;
16         if (args.length > 1) {
17             max = Integer.parseInt(args[1]);
18         }
19         try (PrintWriter fos = new PrintWriter(new File(args[0]), "UTF-8"); ZipInputStream zis = new ZipInputStream(new URL("https://s3.amazonaws.com/alexa-static/top-1m.csv.zip").openStream())) {
20             ZipEntry ze;
21             outer:
22             while ((ze = zis.getNextEntry()) != null) {
23                 System.out.println(ze.getName());
24                 BufferedReader br = new BufferedReader(new InputStreamReader(zis, "UTF-8"));
25                 String line;
26                 while ((line = br.readLine()) != null) {
27                     String[] parts = line.split(",");
28                     int i = Integer.parseInt(parts[0]);
29                     if (i > max) {
30                         zis.close();
31                         break outer;
32                     }
33                     fos.println(parts[1]);
34                     System.out.println(line);
35                 }
36             }
37         }
38     }
39
40 }