Netbiblio: Improve recognition of account errors
@@ -255,8 +255,8 @@ open class NetBiblio : OkHttpBaseApi() {
cover = doc.select(".wo-cover").first()?.attr("src")
details.addAll(doc.select("#lst-fullview_Details .wo-list-label").toList()
.associateWith { label -> label.nextElementSibling() }
- .map {
- entry -> Detail(entry.key.text, entry.value.text)
+ .map { entry ->
+ Detail(entry.key.text, entry.value.text)
})
val description = doc.select(
@@ -278,10 +278,10 @@ open class NetBiblio : OkHttpBaseApi() {
row.select("td").zip(copyCols).forEach { (col, header) ->
val headers = header.split(" / ").map { it.trim() }
val data = col.html().split("<br>").map { it.html.text.trim() }
- headers.zip(data).forEach {
- (type, data) ->
+ headers.zip(data).forEach { (type, data) ->
when (type) {
- "" -> {}
+ "" -> {
+ }
"Bibliothek" -> branch = data
"Aktueller Standort" -> location = data
"Signatur", "Call number", "Cote" -> shelfmark = data
@@ -412,7 +412,7 @@ open class NetBiblio : OkHttpBaseApi() {
override fun account(account: Account): AccountData? {
if (!initialised) start()
- login(account)
+ val login = login(account)
val overview = httpGet("$opacUrl/account", ENCODING).html
val resDoc = httpGet("$opacUrl/account/reservations", ENCODING).html
@@ -420,6 +420,12 @@ open class NetBiblio : OkHttpBaseApi() {
val lentDoc = httpGet("$opacUrl/account/circulations", ENCODING).html
return AccountData(account.id).apply {
+ if (overview.select(".alert").size > 0) {
+ warning = overview.select(".alert").first().ownText()
+ } else if (login.select(".alert").size > 0) {
+ warning = login.select(".alert").first().ownText()
+ }
+
val feesString = overview.select("a[href$=fees]").first()?.text
pendingFees = if (feesString != null) {
Regex("\\(([^\\)]+)\\)").find(feesString)?.groups?.get(1)?.value
@@ -520,7 +526,7 @@ open class NetBiblio : OkHttpBaseApi() {
login(account)
}
- private fun login(account: Account) {
+ private fun login(account: Account): Document {
val formData = FormBody.Builder()
.add("ReturnUrl", "${URL(opacUrl).path}/account")
.add("Username", account.name)
@@ -528,9 +534,10 @@ open class NetBiblio : OkHttpBaseApi() {
.add("SaveUsernameInCookie", "false")
.add("StayLoggedIn", "false").build()
val doc = httpPost("$opacUrl/account/login", formData, ENCODING).html
- if (doc.select(".alert").size > 0) {
+ if (doc.select(".alert").size > 0 && doc.select(".wo-com-account-overview").size < 1) {
throw OpacApi.OpacErrorException(doc.select(".alert").first().ownText())
}
+ return doc
}
override fun getShareUrl(id: String, title: String?): String? {
