|
|
@@ -4,9 +4,6 @@ import balldontlie._
|
|
|
import game.PlayerGameStats
|
|
|
|
|
|
object Extract {
|
|
|
- val stats_output = os.pwd / "stats.json"
|
|
|
- val games_output = os.pwd / "games.json"
|
|
|
-
|
|
|
val selectedTeams = List(
|
|
|
"Phoenix Suns",
|
|
|
"Atlanta Hawks",
|
|
|
@@ -14,16 +11,20 @@ object Extract {
|
|
|
"Milwaukee Bucks"
|
|
|
).take(1)
|
|
|
|
|
|
- def getStats() = {
|
|
|
- val teamIds = EndpointResponse
|
|
|
- .getTeams()
|
|
|
- .filter(team => selectedTeams.contains(team.full_name))
|
|
|
- .map(_.id)
|
|
|
- val gameList = EndpointResponse.getGames(2021, teamIds)
|
|
|
+ def getStats(stats_output: os.Path, games_output: os.Path) = {
|
|
|
+ if (!os.exists(stats_output) || !os.exists(games_output)) {
|
|
|
+ val teamIds = EndpointResponse
|
|
|
+ .getTeams()
|
|
|
+ .filter(team => selectedTeams.contains(team.full_name))
|
|
|
+ .map(_.id)
|
|
|
+ val gameList = EndpointResponse.getGames(2021, teamIds)
|
|
|
|
|
|
- val stats = EndpointResponse.getStats(gameList.map(_.id))
|
|
|
+ val stats = EndpointResponse.getStats(gameList.map(_.id))
|
|
|
|
|
|
- Utils.writeToFile(PlayerGameStats.as_json_value(stats), stats_output)
|
|
|
- Utils.writeToFile(gameList, games_output)
|
|
|
+ Utils.writeToFile(PlayerGameStats.as_json_value(stats), stats_output)
|
|
|
+ Utils.writeToFile(gameList, games_output)
|
|
|
+ } else {
|
|
|
+ println(s"output files $stats_output and $games_output already exist")
|
|
|
+ }
|
|
|
}
|
|
|
}
|