oop-labs-collection/labs/3/lab3lib/Fetcher.java

50 lines
1.5 KiB
Java
Raw Permalink Normal View History

package lab3lib;
//import java.net.URL;
//import java.io.BufferedInputStream;
import java.util.Scanner;
import java.lang.Exception;
//import javax.json.JsonObject;
public class Fetcher {
public void main() {}
/*
private static String fetchString(String remote_url) {
try {
Scanner reader = new Scanner(new URL(remote_url).openStream(), "UTF-8");
String jsonString = "";
if (reader.hasNextLine()) {
jsonString = reader.nextLine();
}
return jsonString;
} catch (Exception e) {
System.out.println("[ERROR] Failed to fetch resource from " + remote_url + " due to the following exception: " + e);
System.exit(1);
}
}
*/
public static StringBuilder fetchTextFromPython() {
try {
Process contentFetcher = Runtime.getRuntime().exec("python3 lab3lib/fetchContent.py");
Scanner reader = new Scanner(contentFetcher.getInputStream());
return new StringBuilder(reader.nextLine());
} catch (Exception e) {
return new StringBuilder("");
}
}
/*
public StringBuilder fetchText(String request) {
String responce = fetchString("http://10.1.1.2:8080/search?language=en-US&format=json&q=" + request);
JSONObject results = new JSONObject(responce);
return results.get("results").get(0).get("content");
}
*/
}
//JSONObject results = 'http://10.1.1.2:8080/search?q=test&language=en-US&format=json'