Repository navigation
Expand file tree
/
Copy pathExport.java
More file actions
40 lines (36 loc) · 1.51 KB
/
Copy pathExport.java
File metadata and controls
40 lines (36 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* Export a list — CSV (signed URL) and JSON (inline, paginated). Free.
*
* mvn -q exec:java -Dexec.mainClass="examples.Export" -Dexec.args="<list_id>"
*/
package examples;
import ai.cleanlist.client.ApiException;
import ai.cleanlist.client.Cleanlist;
import ai.cleanlist.client.model.ExportCsvRequest;
import ai.cleanlist.client.model.ExportCsvResponse;
import ai.cleanlist.client.model.ExportJsonResponse;
public class Export {
public static void main(String[] args) throws ApiException {
if (args.length < 1) {
System.err.println("Usage: Export <list_id>");
System.exit(1);
}
String listId = args[0];
Cleanlist cl = Cleanlist.fromEnv();
// CSV: short-lived signed URL.
ExportCsvResponse signed = cl.export.exportCsv(new ExportCsvRequest().listId(listId));
System.out.printf("CSV: %d rows, %d bytes%n", signed.getRowCount(), signed.getFileSizeBytes());
System.out.printf(" download_url (expires %s): %s%n", signed.getExpiresAt(), signed.getDownloadUrl());
// JSON: rows inline, page by page.
String cursor = null;
int count = 0;
long total = 0;
do {
ExportJsonResponse data = cl.export.exportJson(listId, 500, cursor, null);
count += data.getLeads().size();
total = data.getTotal();
cursor = data.getCursor();
} while (cursor != null && !cursor.isEmpty());
System.out.printf("JSON: streamed %d of %d rows.%n", count, total);
}
}