Skip to content

Commit 3a164d0

Browse files
committed
Begin implementing RobotEvents scraper for event search
1 parent ac15e69 commit 3a164d0

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

app/src/main/java/com/sunkensplashstudios/VRCRoboScout/LookupView.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import com.sunkensplashstudios.VRCRoboScout.ui.theme.*
6666
import kotlinx.coroutines.CoroutineScope
6767
import kotlinx.coroutines.Dispatchers
6868
import kotlinx.coroutines.launch
69+
import kotlinx.coroutines.runBlocking
6970
import kotlinx.coroutines.withContext
7071
import kotlin.math.abs
7172

@@ -112,6 +113,11 @@ class LookupViewModel : ViewModel() {
112113
@Destination
113114
@Composable
114115
fun LookupView(lookupViewModel: LookupViewModel = viewModels["lookup_view"] as LookupViewModel, navController: NavController) {
116+
117+
runBlocking {
118+
println(RoboScoutAPI.roboteventsCompetitionScraper())
119+
}
120+
115121
Column(
116122
modifier = Modifier.fillMaxSize()
117123
) {

app/src/main/java/com/sunkensplashstudios/VRCRoboScout/RoboScoutAPI.kt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,60 @@ class RoboScoutAPI {
252252
}
253253
return data
254254
}
255+
256+
suspend fun roboteventsCompetitionScraper(params: MutableMap<String, Any> = mutableMapOf()): List<String> {
257+
var requestUrl = "https://www.robotevents.com/robot-competitions/vex-robotics-competition"
258+
var params = params
259+
260+
if (!params.containsKey("page")) {
261+
params["page"] = 1
262+
}
263+
264+
if (!params.containsKey("country_id")) {
265+
params["country_id"] = "*"
266+
}
267+
268+
when (params["level_class_id"] as? Int) {
269+
4 -> params["level_class_id"] = 9
270+
5 -> params["level_class_id"] = 12
271+
6 -> params["level_class_id"] = 13
272+
}
273+
274+
when (params["grade_level_id"] as? Int) {
275+
1 -> params["grade_level_id"] = 2
276+
2 -> params["grade_level_id"] = 3
277+
}
278+
279+
val skuArray = mutableListOf<String>()
280+
281+
val response = client.get(requestUrl) {
282+
url {
283+
params.forEach { param ->
284+
if (param.value is List<*>) {
285+
for (value in param.value as List<*>) {
286+
parameters.append("${param.key}[]", value.toString())
287+
}
288+
}
289+
else {
290+
parameters.append(param.key, param.value.toString())
291+
}
292+
}
293+
}
294+
}
295+
296+
println("RobotEvents Scraper (page ${params["page"] as? Int ?: 0}): $requestUrl")
297+
println(response.bodyAsText())
298+
299+
val pattern = "https://www\\.robotevents\\.com/robot-competitions/vex-robotics-competition/RE-VRC([+-]?(?=\\.\\d|\\d)(?:\\d+)?(?:\\.?\\d*))(?:[Ee]([+-]?\\d+))?([+-]?(?=\\.\\d|\\d)(?:\\d+)?(?:\\.?\\d*))(?:[Ee]([+-]?\\d+))?\\.html"
300+
val regex = Regex(pattern, RegexOption.IGNORE_CASE)
301+
val matches = regex.findAll(response.bodyAsText())
302+
303+
for (match in matches) {
304+
skuArray.add(match.value.replace("https://www.robotevents.com/robot-competitions/vex-robotics-competition", "").replace(".html", ""))
305+
}
306+
307+
return skuArray
308+
}
255309
}
256310

257311
suspend fun updateWorldSkillsCache(season: Int? = null) {

0 commit comments

Comments
 (0)