2023-06-10 15:50:10 +03:00
|
|
|
/*
|
|
|
|
* %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/>.
|
|
|
|
*/
|
|
|
|
|
2023-06-08 15:31:50 +03:00
|
|
|
package lab5lib;
|
|
|
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
import java.lang.Exception;
|
|
|
|
|
2023-06-10 15:50:10 +03:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2023-06-08 15:31:50 +03:00
|
|
|
public class Fetcher {
|
|
|
|
/**
|
|
|
|
* Allows to fetch unique strings directly from the search engine
|
|
|
|
*
|
|
|
|
* @since 0.2
|
|
|
|
*
|
2023-06-10 15:50:10 +03:00
|
|
|
* @return String received from the server
|
2023-06-08 15:31:50 +03:00
|
|
|
* @throws Exception in case if the server fails to provide the content
|
|
|
|
*/
|
|
|
|
public static String fetchTextFromPython() throws Exception {
|
|
|
|
try {
|
2023-06-10 15:50:10 +03:00
|
|
|
Process contentFetcher = Runtime.getRuntime()
|
|
|
|
.exec("python3 lab5lib/fetchContent.py");
|
2023-06-08 15:31:50 +03:00
|
|
|
Scanner reader = new Scanner(contentFetcher.getInputStream());
|
|
|
|
return new String(reader.nextLine());
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new Exception("Failed to fetch content from the server");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|