Compare commits
7 Commits
1.3.0
...
6f4cb9fd66
Author | SHA1 | Date | |
---|---|---|---|
6f4cb9fd66
|
|||
1f1374f112
|
|||
b783fb6c4f
|
|||
65dc8ea5d2
|
|||
97efbd0877
|
|||
c62f576ace
|
|||
8ac78d29b1
|
@ -11,11 +11,12 @@ pipeline:
|
||||
event:
|
||||
- tag
|
||||
docker:
|
||||
image: techknowlogick/drone-docker
|
||||
privileged: true
|
||||
image: plugins/docker
|
||||
repo: mosadxyz/tcor
|
||||
secrets: [docker_username, docker_password]
|
||||
tags: latest
|
||||
secrets:
|
||||
- username: docker_username
|
||||
password: docker_password
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
|
@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'org.mosad'
|
||||
version '1.3.0'
|
||||
version '1.2.7'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -48,8 +48,8 @@ class APIController {
|
||||
private val logger: Logger = LoggerFactory.getLogger(APIController::class.java)
|
||||
|
||||
companion object {
|
||||
const val apiVersion = "1.3.0"
|
||||
const val softwareVersion = "1.3.0"
|
||||
const val apiVersion = "1.2.0"
|
||||
const val softwareVersion = "1.2.8"
|
||||
val startTime = System.currentTimeMillis() / 1000
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,6 @@ data class MensaMeta(val updateTime: Long, val mensaName: String)
|
||||
data class MensaMenu(val meta: MensaMeta, val currentWeek: MensaWeek, val nextWeek: MensaWeek)
|
||||
|
||||
// data classes for the timetable part
|
||||
|
||||
data class CalendarWeek(val week: Int, val year: Int)
|
||||
|
||||
data class Lesson(
|
||||
val lessonID: String,
|
||||
val lessonSubject: String,
|
||||
@ -61,7 +58,7 @@ data class TimetableDay(val timeslots: Array<ArrayList<Lesson>> = Array(6) { Arr
|
||||
|
||||
data class TimetableWeek(val days: Array<TimetableDay> = Array(6) { TimetableDay() })
|
||||
|
||||
data class TimetableCourseMeta(var updateTime: Long = 0, val courseName: String = "", val weekIndex: Int = 0, var weekNumberYear: Int = 0, val year: Int = 0, val link: String = "")
|
||||
data class TimetableCourseMeta(var updateTime: Long = 0, val courseName: String = "", val weekIndex: Int = 0, var weekNumberYear: Int = 0, val link: String = "")
|
||||
|
||||
data class TimetableCourseWeek(val meta: TimetableCourseMeta = TimetableCourseMeta(), var timetable: TimetableWeek = TimetableWeek())
|
||||
|
||||
|
@ -33,9 +33,9 @@ import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.*
|
||||
import java.util.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.collections.HashMap
|
||||
import kotlin.collections.HashSet
|
||||
import kotlin.concurrent.scheduleAtFixedRate
|
||||
import kotlin.time.Duration
|
||||
@ -53,7 +53,7 @@ class CacheController {
|
||||
|
||||
var courseList = CoursesList(CoursesMeta(), sortedMapOf())
|
||||
var mensaMenu = MensaMenu(MensaMeta(0, ""), MensaWeek(), MensaWeek())
|
||||
var timetableList = ConcurrentHashMap<String, TimetableCourseWeek>() // this list contains all timetables
|
||||
var timetableList = HashMap<String, TimetableCourseWeek>() // this list contains all timetables
|
||||
|
||||
/**
|
||||
* get a timetable, since they may not be cached, we need to make sure it's cached, otherwise download
|
||||
@ -68,7 +68,6 @@ class CacheController {
|
||||
val currentTime = System.currentTimeMillis() / 1000
|
||||
val timetableLink = "https://mosad.xyz"
|
||||
val weekNumberYear = 0
|
||||
val year = 0
|
||||
val instr = CacheController::class.java.getResourceAsStream("/html/Timetable_normal-week.html")
|
||||
|
||||
val timetableParser =
|
||||
@ -81,7 +80,6 @@ class CacheController {
|
||||
courseName,
|
||||
weekIndex,
|
||||
weekNumberYear,
|
||||
year,
|
||||
timetableLink
|
||||
), timetableTest ?: TimetableWeek()
|
||||
)
|
||||
@ -97,7 +95,7 @@ class CacheController {
|
||||
val currentTime = System.currentTimeMillis() / 1000
|
||||
|
||||
val timetableParser = TimetableParser(timetableLink)
|
||||
val calendarWeek = timetableParser.parseCalendarWeek()
|
||||
val weekNumberYear = timetableParser.parseWeekNumberYear()
|
||||
val timetable = timetableParser.parseTimeTable()
|
||||
|
||||
TimetableCourseWeek(
|
||||
@ -105,11 +103,10 @@ class CacheController {
|
||||
currentTime,
|
||||
courseName,
|
||||
weekIndex,
|
||||
calendarWeek?.week ?: 0,
|
||||
calendarWeek?.year ?: 0,
|
||||
weekNumberYear ?: 0,
|
||||
timetableLink
|
||||
), timetable ?: TimetableWeek()
|
||||
).also { if (timetable != null) timetableList[key] = it }
|
||||
).also { timetableList[key] = it }
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,7 +198,7 @@ class CacheController {
|
||||
val timetableParser = TimetableParser(timetableCourse.value.meta.link)
|
||||
timetableCourse.value.timetable = timetableParser.parseTimeTable() ?: return@execute
|
||||
timetableCourse.value.meta.weekNumberYear =
|
||||
timetableParser.parseCalendarWeek()?.week ?: return@execute
|
||||
timetableParser.parseWeekNumberYear() ?: return@execute
|
||||
timetableCourse.value.meta.updateTime = System.currentTimeMillis() / 1000
|
||||
|
||||
saveTimetableToCache(timetableCourse.value) // save the updated timetable to the cache directory
|
||||
|
@ -22,11 +22,8 @@
|
||||
|
||||
package org.mosad.thecitadelofricks.hsoparser
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.sync.Semaphore
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import org.mosad.thecitadelofricks.CalendarWeek
|
||||
import org.mosad.thecitadelofricks.Lesson
|
||||
import org.mosad.thecitadelofricks.TimetableWeek
|
||||
import org.slf4j.LoggerFactory
|
||||
@ -39,33 +36,31 @@ class TimetableParser(timetableURL: String? = null, htmlDoc: Document? = null) {
|
||||
private var logger: org.slf4j.Logger = LoggerFactory.getLogger(TimetableParser::class.java)
|
||||
private val days = arrayOf("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
|
||||
|
||||
companion object {
|
||||
val semaphore = Semaphore(3, 0)
|
||||
}
|
||||
|
||||
private val htmlDoc: Document? = htmlDoc ?: timetableURL?.let {
|
||||
runBlocking {
|
||||
try {
|
||||
// Only allow sending a limited amount of requests at the same time
|
||||
semaphore.acquire()
|
||||
Jsoup.connect(timetableURL).get()
|
||||
} catch (gex: Exception) {
|
||||
logger.error("general TimetableParser error", gex)
|
||||
private val htmlDoc: Document? =
|
||||
htmlDoc
|
||||
?: if (timetableURL == null) {
|
||||
null
|
||||
} finally {
|
||||
semaphore.release()
|
||||
} else {
|
||||
try {
|
||||
Jsoup.connect(timetableURL).get()
|
||||
} catch (gex: Exception) {
|
||||
logger.error("general TimetableParser error", gex)
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the timetable from the previously given url
|
||||
* the timetable is organised per row not per column;
|
||||
* Mon 1, Tue 1, Wed 1, Thur 1, Fri 1, Sat 1, Mon 2 and so on
|
||||
*/
|
||||
fun parseTimeTable(): TimetableWeek? = htmlDoc?.let {
|
||||
fun parseTimeTable(): TimetableWeek? {
|
||||
if (htmlDoc == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
val timetableWeek = TimetableWeek()
|
||||
val rows = it.select("table.timetable").select("tr[scope=\"row\"]")
|
||||
val rows = htmlDoc.select("table.timetable").select("tr[scope=\"row\"]")
|
||||
|
||||
var sDay = -1
|
||||
var sRow = -1
|
||||
@ -132,13 +127,15 @@ class TimetableParser(timetableURL: String? = null, htmlDoc: Document? = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the calendar week and the associated year for the timetable
|
||||
* parse the week number of the year for the timetable
|
||||
*/
|
||||
fun parseCalendarWeek(): CalendarWeek? = htmlDoc?.let {
|
||||
val dateStr = it.select("h1.timetable-caption").text().substringAfter("- ")
|
||||
val week = dateStr.substringBefore(".").replace(" ", "").toInt()
|
||||
val year = dateStr.substringAfter("Woche ").replace(" ", "").toInt()
|
||||
CalendarWeek(week, year)
|
||||
fun parseWeekNumberYear(): Int? {
|
||||
if (htmlDoc == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return htmlDoc.select("h1.timetable-caption").text().substringAfter("- ")
|
||||
.substringBefore(".").replace(" ", "").toInt()
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
|
@ -25,7 +25,6 @@ package org.mosad.thecitadelofricks.hsoparser
|
||||
import org.jsoup.Jsoup
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mosad.thecitadelofricks.CalendarWeek
|
||||
import java.io.File
|
||||
|
||||
class TimetableParserTest {
|
||||
@ -51,11 +50,11 @@ class TimetableParserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseCalendarWeek() {
|
||||
fun parseWeekNumberYear() {
|
||||
val htmlFile = File(TimetableParserTest::class.java.getResource("/html/Timetable_normal-week.html").path)
|
||||
val htmlDoc = Jsoup.parse(htmlFile, "UTF-8", "https://www.hs-offenburg.de/")
|
||||
val actualCalendarWeek = TimetableParser(htmlDoc = htmlDoc).parseCalendarWeek()
|
||||
val actualWeekNumberYear = TimetableParser(htmlDoc = htmlDoc).parseWeekNumberYear()
|
||||
|
||||
Assertions.assertEquals(CalendarWeek(42, 2019), actualCalendarWeek)
|
||||
Assertions.assertEquals(42, actualWeekNumberYear)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user