package com.nhlreplay

import converter.xhtml.XhtmlConverter
import parser.playbyplay.GameEventParser
import parser.reports.{GameReportSource, GameReportsParser}
import utils.FileUtils

object Main
{
  val playByPlayPath = "src/test/resources/playbyplay"

  def main(args: Array[String]) {
    val gameReports = retrieveGameReports()
    val playByPlayReportFile = retrievePlayByPlayReport(gameReports.head.playByPlayURL)
    parsePlayByPlay(playByPlayReportFile)
  }

  private def retrieveGameReports() = {
    val gameReportFile = GameReportSource.getReportsByTeam("TOR")
    val xhtmlFile = XhtmlConverter.convertHtml(gameReportFile)
    GameReportsParser.parse(xhtmlFile)
  }

  private def retrievePlayByPlayReport(reportURL: String) = {
    val fileName = reportURL.substring(reportURL.lastIndexOf("/"))
    FileUtils.retrieveFile(reportURL, playByPlayPath + fileName)
  }

  private def parsePlayByPlay(reportPath: String) {
    val xhtmlFile = XhtmlConverter.convertHtml(reportPath)
    val gameInfo = GameEventParser.parse(xhtmlFile)
    gameInfo.writeToJsonpFile("../client/src/main/jsonp/data.jsonp")
  }
}

package com.nhlreplay

import converter.xhtml.XhtmlConverter
import parser.playbyplay.GameEventParser
import parser.reports.{GameReportSource, GameReportsParser}
import utils.FileUtils

object Main
{
  val playByPlayPath = "src/test/resources/playbyplay"

  def main(args: Array[String]) {
    val playByPlayReportFile = {
      if (args.length > 0) playByPlayPath + "/" + args.head
      else retrievePlayByPlayReport(retrieveGameReports().head.playByPlayURL)
    }
    parsePlayByPlay(playByPlayReportFile)
  }

  private def retrieveGameReports() = {
    val gameReportFile = GameReportSource.getReportsByTeam("TOR")
    val xhtmlFile = XhtmlConverter.convertHtml(gameReportFile)
    GameReportsParser.parse(xhtmlFile)
  }

  private def retrievePlayByPlayReport(reportURL: String) = {
    val fileName = reportURL.substring(reportURL.lastIndexOf("/"))
    FileUtils.retrieveFile(reportURL, playByPlayPath + fileName)
  }

  private def parsePlayByPlay(reportPath: String) {
    val xhtmlFile = {
      if (reportPath.toLowerCase.endsWith(".xhtml")) reportPath
      else XhtmlConverter.convertHtml(reportPath)
    }
    val gameInfo = GameEventParser.parse(xhtmlFile)
    gameInfo.writeToJsonpFile("../client/src/main/jsonp/data.jsonp")
  }
}

Support passing local XHTML or HTM play-by-play file as command line argument
Support passing local XHTML or HTM play-by-play file as command line argument
