/* * %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 . */ package lab5lib; import java.util.Scanner; import java.lang.Exception; /** * 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 { /** * 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 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"); } } }