|
a |
|
b/scripts/gatherfullids.java |
|
|
1 |
import java.util.*; |
|
|
2 |
import java.io.*; |
|
|
3 |
import java.net.*; |
|
|
4 |
public class gatherfullids { |
|
|
5 |
public static void main(String[] args) throws Exception { |
|
|
6 |
PrintWriter out = new PrintWriter(new File("fullctrpids.csv")); |
|
|
7 |
for (int i = 0; i < 9455; i+=50) { |
|
|
8 |
String source = getURLSource("https://clinicaltrialsapi.cancer.gov/v1/clinical-trials?size=50&from=" + i + "&study_protocol_type=interventional&include=nct_id"); |
|
|
9 |
int index = source.indexOf("NCT"); |
|
|
10 |
while (index != -1) { |
|
|
11 |
out.println(source.substring(index, index + 11)); |
|
|
12 |
index = source.indexOf("NCT", index+1); |
|
|
13 |
} |
|
|
14 |
} |
|
|
15 |
out.close(); |
|
|
16 |
} |
|
|
17 |
public static String getURLSource(String url) throws IOException |
|
|
18 |
{ |
|
|
19 |
URL urlObject = new URL(url); |
|
|
20 |
URLConnection urlConnection = urlObject.openConnection(); |
|
|
21 |
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); |
|
|
22 |
try { |
|
|
23 |
return toString(urlConnection.getInputStream());}catch(Exception e) {return "";} |
|
|
24 |
} |
|
|
25 |
private static String toString(InputStream inputStream) throws IOException |
|
|
26 |
{ |
|
|
27 |
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))) |
|
|
28 |
{ |
|
|
29 |
String inputLine; |
|
|
30 |
StringBuilder stringBuilder = new StringBuilder(); |
|
|
31 |
while ((inputLine = bufferedReader.readLine()) != null) |
|
|
32 |
{ |
|
|
33 |
stringBuilder.append(inputLine); |
|
|
34 |
} |
|
|
35 |
|
|
|
36 |
return stringBuilder.toString(); |
|
|
37 |
} |
|
|
38 |
} |
|
|
39 |
|
|
|
40 |
} |