<commit_before>package scorex.client

import java.io.{BufferedReader, InputStreamReader}
import java.net.{HttpURLConnection, URL}

import play.libs.Json
import scorex.app.LagonakiSettings

import scala.io.StdIn
import scala.util.Try


class ApiClient(settings: LagonakiSettings) {

  def executeCommand(command: String): String = {
    if (command.equals("help")) {
      "<method> <url> <data> \n Type quit to stop."
    } else Try {
      val args = command.split(" ")
      val method = args.head.toUpperCase
      val path = args(1)

      val content = if (method.equals("POST")) {
        command.substring((method + " " + path + " ").length())
      } else ""

      val url = new URL("http://127.0.0.1:" + settings.rpcPort + "/" + path)
      val connection = url.openConnection().asInstanceOf[HttpURLConnection]
      connection.setRequestMethod(method)

      if (method.equals("POST")) {
        connection.setDoOutput(true)
        connection.getOutputStream.write(content.getBytes)
        connection.getOutputStream.flush()
        connection.getOutputStream.close()
      }

      val stream = connection.getResponseCode match {
        case 200 => connection.getInputStream
        case _ => connection.getErrorStream
      }

      val isReader = new InputStreamReader(stream)
      val br = new BufferedReader(isReader)
      val result = br.readLine()

      Try(Json.parse(result)).map(_.toString).getOrElse(result)
    }.getOrElse("Invalid command! \n Type help to get a list of commands.")
  }
}

object ApiClient {
  def main(args: Array[String]): Unit = {
    val settingsFilename = args.headOption.getOrElse("settings.json")
    val settings = new LagonakiSettings(settingsFilename)
    val apiClient = new ApiClient(settings)

    println("Welcome to the Scorex command-line client...")
    Iterator.continually(StdIn.readLine()).takeWhile(!_.equals("quit")).foreach { command =>
      println(s"[$command RESULT] " + apiClient.executeCommand(command))<commit_msg>error output<commit_after>package scorex.client

import java.io.{BufferedReader, InputStreamReader}
import java.net.{HttpURLConnection, URL}

import play.libs.Json
import scorex.app.LagonakiSettings

import scala.io.StdIn
import scala.util.{Failure, Success, Try}


class ApiClient(settings: LagonakiSettings) {

  def executeCommand(command: String): String = {
    if (command.equals("help")) {
      "<method> <url> <data> \n Type quit to stop."
    } else Try {
      val args = command.split(" ")
      val method = args.head.toUpperCase
      val path = args(1)

      val content = if (method.equals("POST")) {
        command.substring((method + " " + path + " ").length())
      } else ""

      val url = new URL("http://127.0.0.1:" + settings.rpcPort + "/" + path)
      val connection = url.openConnection().asInstanceOf[HttpURLConnection]
      connection.setRequestMethod(method)

      if (method.equals("POST")) {
        connection.setDoOutput(true)
        connection.getOutputStream.write(content.getBytes)
        connection.getOutputStream.flush()
        connection.getOutputStream.close()
      }

      val stream = connection.getResponseCode match {
        case 200 => connection.getInputStream
        case _ => connection.getErrorStream
      }

      val isReader = new InputStreamReader(stream)
      val br = new BufferedReader(isReader)
      val result = br.readLine()

      Try(Json.parse(result)).map(_.toString)
    }.flatten match {
      case Success(result) => result
      case Failure(e) =>
        s"Problem occurred $e! \n Type help to get a list of commands."
    }
  }
}

object ApiClient {
  def main(args: Array[String]): Unit = {
    val settingsFilename = args.headOption.getOrElse("settings.json")
    val settings = new LagonakiSettings(settingsFilename)
    val apiClient = new ApiClient(settings)

    println("Welcome to the Scorex command-line client...")
    Iterator.continually(StdIn.readLine()).takeWhile(!_.equals("quit")).foreach { command =>
      println(s"[$command RESULT] " + apiClient.executeCommand(command))
{'fraction_non_alphanumeric': 0.12490779444307844, 'fraction_numerical': 0.004917629702483403, 'mean_word_length': 3.268625393494229, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5553893', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1167, 'n_words': 266}