lab5: finish all tasks

This commit is contained in:
2023-06-10 15:50:10 +03:00
parent 102089cb23
commit 58becbe55e
8 changed files with 670 additions and 132 deletions
+30 -34
View File
@@ -1,56 +1,52 @@
/*
* %W% %E% Dymik739
* Email: dymik739@109.86.70.81
*
* Copyright (C) 2023 FIOT Dev Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package lab5lib;
//import java.net.URL;
//import java.io.BufferedInputStream;
import java.util.Scanner;
import java.lang.Exception;
//import javax.json.JsonObject;
/**
* Class used as a connector for fetching content from Internet to provide
* the application with random text at every startup.
*
* @since 0.2
* @author Dymik739
*/
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);
}
}
*/
/**
* Allows to fetch unique strings directly from the search engine
*
* @since 0.2
*
* @return String received from the server
* @throws Exception in case if the server fails to provide the content
*/
public static String fetchTextFromPython() throws Exception {
try {
Process contentFetcher = Runtime.getRuntime().exec("python3 lab3lib/fetchContent.py");
Process contentFetcher = Runtime.getRuntime()
.exec("python3 lab5lib/fetchContent.py");
Scanner reader = new Scanner(contentFetcher.getInputStream());
return new String(reader.nextLine());
} catch (Exception e) {
throw new Exception("Failed to fetch content from the server");
}
}
/*
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'