|
|
@@ -17,6 +17,7 @@ object ResponseMetadata {
|
|
|
|
|
|
object Utils {
|
|
|
val get_json = (endpoint: String, params: Iterable[(String, String)]) => {
|
|
|
+ Thread.sleep(200) // A dirty way to not flood the server with requests
|
|
|
val r = requests.get(
|
|
|
endpoint,
|
|
|
params = params
|
|
|
@@ -36,15 +37,19 @@ object GamesResponse {
|
|
|
val endpoint = "https://www.balldontlie.io/api/v1/games"
|
|
|
|
|
|
val getGames = (season: Int, teams: List[Int]) => {
|
|
|
- val baseParams = Map(
|
|
|
- "seasons[]" -> List(season).mkString(","),
|
|
|
- "team_ids[]" -> teams.mkString(",")
|
|
|
- )
|
|
|
- val json =
|
|
|
- Utils.get_json(endpoint, baseParams)
|
|
|
+ // Using an array as param to team_ids[] yields a 500 error so we make
|
|
|
+ // several requests instead
|
|
|
+ teams.flatMap(team => {
|
|
|
+ val baseParams = Map(
|
|
|
+ "seasons[]" -> List(season).mkString(","),
|
|
|
+ "team_ids[]" -> team.toString()
|
|
|
+ )
|
|
|
+ val json =
|
|
|
+ Utils.get_json(endpoint, baseParams)
|
|
|
|
|
|
- val response: GamesResponse = upickle.default.read[GamesResponse](json)
|
|
|
- response.data
|
|
|
+ val response: GamesResponse = upickle.default.read[GamesResponse](json)
|
|
|
+ response.data
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
|