-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only store the data we actually use of the locations
- Loading branch information
Showing
9 changed files
with
64 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
app/src/test/java/nl/ovfietsbeschikbaarheid/LocationsCrawler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package nl.ovfietsbeschikbaarheid | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.client.request.get | ||
import io.ktor.serialization.kotlinx.json.json | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import java.io.File | ||
|
||
/** | ||
* Not a test, rather a tool. Added in the test folder to prevent it being added in the app. | ||
*/ | ||
object LocationsCrawler { | ||
private val json = Json { | ||
ignoreUnknownKeys = true | ||
} | ||
|
||
private val httpClient = HttpClient { | ||
install(ContentNegotiation) { | ||
json(json) | ||
} | ||
} | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>): Unit = runBlocking { | ||
val loaded = httpClient.get("http://fiets.openov.nl/locations.json").body<LocationsDTO>() | ||
val asJson = json.encodeToString(loaded) | ||
val file = File("app/src/main/res/raw/locations.json") | ||
file.writeText(asJson) | ||
} | ||
} | ||
|
||
@Serializable | ||
data class LocationsDTO( | ||
val locaties: Map<String, Location> | ||
) | ||
|
||
@Serializable | ||
data class Location( | ||
val description: String, | ||
val stationCode: String, | ||
val lat: Double, | ||
val lng: Double, | ||
val extra: LocationExtra, | ||
val link: Link | ||
) | ||
|
||
@Serializable | ||
data class Link( | ||
val uri: String | ||
) | ||
|
||
@Serializable | ||
data class LocationExtra( | ||
val locationCode: String, | ||
) |