forked from github/szkolny
[API/Mobidziennik] Use toIntOrNull instead of try catch in the lucky number extractor.
This commit is contained in:
parent
a96fcabba5
commit
d735dcea05
@ -8,6 +8,7 @@ import pl.szczodrzynski.edziennik.data.api.Regexes
|
|||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.DataMobidziennik
|
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.DataMobidziennik
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.luckynumber.LuckyNumber
|
import pl.szczodrzynski.edziennik.data.db.modules.luckynumber.LuckyNumber
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||||
|
import pl.szczodrzynski.edziennik.get
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
|
||||||
class MobidziennikLuckyNumberExtractor(val data: DataMobidziennik, text: String) {
|
class MobidziennikLuckyNumberExtractor(val data: DataMobidziennik, text: String) {
|
||||||
@ -15,14 +16,11 @@ class MobidziennikLuckyNumberExtractor(val data: DataMobidziennik, text: String)
|
|||||||
data.profile?.luckyNumber = -1
|
data.profile?.luckyNumber = -1
|
||||||
data.profile?.luckyNumberDate = null
|
data.profile?.luckyNumberDate = null
|
||||||
|
|
||||||
Regexes.MOBIDZIENNIK_LUCKY_NUMBER.find(text)?.let {
|
Regexes.MOBIDZIENNIK_LUCKY_NUMBER.find(text)?.get(1)?.toIntOrNull()?.let {
|
||||||
try {
|
|
||||||
val luckyNumber = it.groupValues[1].toInt()
|
|
||||||
|
|
||||||
val luckyNumberObject = LuckyNumber(
|
val luckyNumberObject = LuckyNumber(
|
||||||
data.profileId,
|
data.profileId,
|
||||||
Date.getToday(),
|
Date.getToday(),
|
||||||
luckyNumber
|
it
|
||||||
)
|
)
|
||||||
|
|
||||||
data.luckyNumberList.add(luckyNumberObject)
|
data.luckyNumberList.add(luckyNumberObject)
|
||||||
@ -35,7 +33,6 @@ class MobidziennikLuckyNumberExtractor(val data: DataMobidziennik, text: String)
|
|||||||
data.profile?.empty ?: false,
|
data.profile?.empty ?: false,
|
||||||
System.currentTimeMillis()
|
System.currentTimeMillis()
|
||||||
))
|
))
|
||||||
} catch (_: Exception){}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user