|
|
@@ -6,47 +6,47 @@ import upickle.default._
|
|
|
|
|
|
object Extract {
|
|
|
def writeOrReadBack[T: ReadWriter](
|
|
|
- file: os.Path,
|
|
|
+ localCopy: os.Path,
|
|
|
getRemoteData: () => T
|
|
|
): T = {
|
|
|
- if (!os.exists(file)) {
|
|
|
+ if (!os.exists(localCopy)) {
|
|
|
val data = getRemoteData()
|
|
|
- Utils.writeToFile[T](data, file)
|
|
|
+ Utils.writeToFile[T](data, localCopy)
|
|
|
|
|
|
data
|
|
|
} else {
|
|
|
- println(s"file $file already exists, reading back from it")
|
|
|
- Utils.readFromFile[T](file)
|
|
|
+ println(s"file $localCopy already exists, reading back from it")
|
|
|
+ Utils.readFromFile[T](localCopy)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- def getTeams(output: os.Path, filterTeams: Team => Boolean) = {
|
|
|
+ def getTeams(local: os.Path, filterTeams: Team => Boolean) = {
|
|
|
def getData() = {
|
|
|
EndpointResponse
|
|
|
.getTeams()
|
|
|
.filter(filterTeams)
|
|
|
}
|
|
|
|
|
|
- writeOrReadBack(output, getData)
|
|
|
+ writeOrReadBack(local, getData)
|
|
|
}
|
|
|
|
|
|
- def getGames(output: os.Path, season: Int, teamIds: List[Int]) = {
|
|
|
+ def getGames(local: os.Path, season: Int, teamIds: List[Int]) = {
|
|
|
def getData() = {
|
|
|
EndpointResponse.getGames(2021, teamIds)
|
|
|
}
|
|
|
|
|
|
- writeOrReadBack(output, getData)
|
|
|
+ writeOrReadBack(local, getData)
|
|
|
}
|
|
|
|
|
|
- def getStats(file: os.Path, gameIds: List[Int]) = {
|
|
|
- if (!os.exists(file)) {
|
|
|
+ def getStats(local: os.Path, gameIds: List[Int]) = {
|
|
|
+ if (!os.exists(local)) {
|
|
|
val data = EndpointResponse.getStats(gameIds)
|
|
|
- Utils.writeToFile(PlayerGameStats.as_json_value(data), file)
|
|
|
+ Utils.writeToFile(PlayerGameStats.as_json_value(data), local)
|
|
|
|
|
|
data
|
|
|
} else {
|
|
|
- println(s"file $file already exists, reading back from it")
|
|
|
- Utils.readFromFile[List[PlayerGameStats]](file)
|
|
|
+ println(s"file $local already exists, reading back from it")
|
|
|
+ Utils.readFromFile[List[PlayerGameStats]](local)
|
|
|
}
|
|
|
}
|
|
|
}
|