<commit_before>/*
 * Copyright (c) 2012 Orderly Ltd. All rights reserved.
 *
 * This program is licensed to you under the Apache License Version 2.0,
 * and you may not use this file except in compliance with the Apache License Version 2.0.
 * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the Apache License Version 2.0 is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
 */
package co.orderly.dutch

// Java
import java.io.File
import java.io.FileReader

// Config
import com.typesafe.config.{Config, ConfigFactory}

// Scala
import scala.collection.JavaConversions._

// opencsv
import au.com.bytecode.opencsv._
import bean.CsvToBean

// Amazon MWS Products
import com.amazonservices.mws.products.{MarketplaceWebServiceProductsConfig, MarketplaceWebServiceProductsClient}
// import com.amazonservices.mws.products.model.*

// Dutch
import csv._

/**
 * Pricer performs the competitive pricing
 */
case class Pricer(config: Config,
                  input: Seq[File],
                  separator: Char,
                  quoteChar: Char,
                  header: Boolean,
                  output: String) {

  /**
   * Executes a pricing run
   */
  def run() {
    Console.println("Running pricing!")

    // for( ln <- io.Source.stdin.getLines ) println( ln )

    val line = if (header) 1 else 0

    // TODO: eurgh, assumes one file passed in
    val csvReader = new CSVReader(new FileReader(input(0)), separator, quoteChar, line)
    InputFile.asCsv.parse(InputFile.mappingStrategy, csvReader).foreach(_.debug())

    val client = initClient(config.getConfig("merchant"))
  }

  /**
   * Initializes an Amazon MWS Products Client
   */
  protected def initClient(config: Config) = new MarketplaceWebServiceProductsClient(
    config.getString("key"),     // awsAccessKeyId
    config.getString("secret"),  // awsSecretAccessKey
    config.getString("app"),     // applicationName
    config.getString("version"), // applicationVersion
    initClientConfig(config.getString("locale")) // config
  )

  /**<commit_msg>Updated Pricer (still having problems with Apache HttpClient not being found)<commit_after>/*
 * Copyright (c) 2012 Orderly Ltd. All rights reserved.
 *
 * This program is licensed to you under the Apache License Version 2.0,
 * and you may not use this file except in compliance with the Apache License Version 2.0.
 * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the Apache License Version 2.0 is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
 */
package co.orderly.dutch

// Java
import java.io.File
import java.io.FileReader

// Config
import com.typesafe.config.{Config, ConfigFactory}

// Scala
import scala.collection.JavaConversions._

// opencsv
import au.com.bytecode.opencsv._
import bean.CsvToBean

// Amazon MWS Products
import com.amazonservices.mws.products.{MarketplaceWebServiceProductsConfig, MarketplaceWebServiceProductsClient}
// import com.amazonservices.mws.products.model.*

// Dutch
import csv._

/**
 * Pricer performs the competitive pricing
 */
case class Pricer(config: Config,
                  input: Seq[File],
                  separator: Char,
                  quoteChar: Char,
                  header: Boolean,
                  output: String) {

  /**
   * Executes a pricing run
   */
  def run() {
    Console.println("Running pricing!")

    // for( ln <- io.Source.stdin.getLines ) println( ln )

    val line = if (header) 1 else 0

    // TODO: eurgh, assumes one file passed in
    val csvReader = new CSVReader(new FileReader(input(0)), separator, quoteChar, line)
    InputFile.asCsv.parse(InputFile.mappingStrategy, csvReader).foreach(_.debug())

    val client = initClient(config.getConfig("merchant"))

    /*
       GetCompetitivePricingForASINRequest request = new GetCompetitivePricingForASINRequest();
request.setSellerId(ProductsConfig.sellerId);
request.setMarketplaceId(ProductsConfig.marketplaceId);
List<String> asins = new ArrayList<String>();
asins.add("B004QNYOXQ");
request.setASINList(new ASINListType(asins));
     */

  }

  /**
   * Initializes an Amazon MWS Products Client
   */
  protected def initClient(config: Config) = new MarketplaceWebServiceProductsClient(
    config.getString("key"),     // awsAccessKeyId
    config.getString("secret"),  // awsSecretAccessKey
    config.getString("app"),     // applicationName
    config.getString("version"), // applicationVersion
    initClientConfig(config.getString("locale")) // config
  )

  /**
{'fraction_non_alphanumeric': 0.0999607996863975, 'fraction_numerical': 0.008036064288514309, 'mean_word_length': 3.3690068493150687, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, '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': '4545503', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1395, 'n_words': 449}