Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
1d614a06c4
|
|||
3f10c8afaa
|
|||
9de1e295dd
|
|||
6287d4582d
|
|||
7dfa0fc6c4
|
|||
a53b2b8fc1
|
|||
36972c9322
|
|||
7bf2920d17
|
|||
c30306c163
|
|||
46c9a61124
|
|||
36acf1a00a
|
|||
f9029bf1c3
|
|||
fe72c02562
|
|||
8d9fcd3d7c
|
|||
ec7a0a7a64
|
|||
efd8f9f9f5
|
|||
e2dce9fab3
|
|||
bbac0d3688 | |||
6114077591
|
21
.drone.yml
21
.drone.yml
@ -7,3 +7,24 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- gradle test
|
- gradle test
|
||||||
|
|
||||||
|
- name: build
|
||||||
|
image: gradle:jdk11
|
||||||
|
commands:
|
||||||
|
- gradle bootJar
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
|
||||||
|
- name: docker
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
repo: mosadxyz/tcor
|
||||||
|
tags:
|
||||||
|
- latest
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
8
Dockerfile
Normal file
8
Dockerfile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
FROM adoptopenjdk/openjdk11:alpine-jre
|
||||||
|
RUN addgroup -S spring && adduser -S spring -G spring
|
||||||
|
#RUN groupadd -r spring && useradd -r -g spring spring # for openjdk:xx builds
|
||||||
|
USER spring:spring
|
||||||
|
ARG JAR_FILE=build/libs/*.jar
|
||||||
|
COPY ${JAR_FILE} thecitadelofricks.jar
|
||||||
|
ENTRYPOINT ["java","-Djavax.net.ssl.trustStore=/tcor/cacerts", "-Djavax.net.ssl.trustStorePassword=changeit", "-jar","/thecitadelofricks.jar"]
|
||||||
|
VOLUME /tcor
|
@ -1,3 +1,4 @@
|
|||||||
|

|
||||||
[](https://drone.mosad.xyz/Seil0/TheCitadelofRicks)
|
[](https://drone.mosad.xyz/Seil0/TheCitadelofRicks)
|
||||||
[](https://git.mosad.xyz/Seil0/TheCitadelofRicks/releases)
|
[](https://git.mosad.xyz/Seil0/TheCitadelofRicks/releases)
|
||||||
[](https://www.gnu.org/licenses/gpl-3.0)
|
[](https://www.gnu.org/licenses/gpl-3.0)
|
||||||
|
15
build.gradle
15
build.gradle
@ -1,12 +1,12 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'org.jetbrains.kotlin.jvm' version '1.3.70'
|
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
|
||||||
id 'org.jetbrains.kotlin.plugin.spring' version '1.3.70'
|
id 'org.jetbrains.kotlin.plugin.spring' version '1.3.72'
|
||||||
id 'org.springframework.boot' version '2.2.5.RELEASE'
|
id 'org.springframework.boot' version '2.3.2.RELEASE'
|
||||||
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
|
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'org.mosad'
|
group 'org.mosad'
|
||||||
version '1.2.2'
|
version '1.2.7'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
@ -14,13 +14,12 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-reflect'
|
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
|
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8'
|
||||||
implementation 'org.jsoup:jsoup:1.12.2'
|
implementation 'org.jsoup:jsoup:1.13.1'
|
||||||
implementation 'com.google.code.gson:gson:2.8.6'
|
implementation 'com.google.code.gson:gson:2.8.6'
|
||||||
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.0'
|
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
2
gradlew
vendored
2
gradlew
vendored
@ -82,6 +82,7 @@ esac
|
|||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
@ -129,6 +130,7 @@ fi
|
|||||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||||
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
# We build the pattern for arguments to be converted via cygpath
|
||||||
|
4
gradlew.bat
vendored
4
gradlew.bat
vendored
@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
|
|||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
@ -81,6 +84,7 @@ set CMD_LINE_ARGS=%*
|
|||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.RequestParam
|
|||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
class APIController {
|
class APIController {
|
||||||
@ -47,8 +48,8 @@ class APIController {
|
|||||||
private val logger: Logger = LoggerFactory.getLogger(APIController::class.java)
|
private val logger: Logger = LoggerFactory.getLogger(APIController::class.java)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val apiVersion = "1.1.4"
|
const val apiVersion = "1.2.0"
|
||||||
const val softwareVersion = "1.2.2"
|
const val softwareVersion = "1.2.7"
|
||||||
val startTime = System.currentTimeMillis() / 1000
|
val startTime = System.currentTimeMillis() / 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,18 +58,12 @@ class APIController {
|
|||||||
CacheController()
|
CacheController()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove this with API version 2.0.0
|
|
||||||
@Deprecated("courses is replaced by courseList", replaceWith = ReplaceWith("courseList()"))
|
|
||||||
@RequestMapping("/courses")
|
|
||||||
fun courses(): CoursesList {
|
|
||||||
return courseList()
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping("/courseList")
|
@RequestMapping("/courseList")
|
||||||
fun courseList(): CoursesList {
|
fun courseList(): CoursesListRet {
|
||||||
logger.info("courseList request at ${LocalDateTime.now()}!")
|
logger.info("courseList request at ${LocalDateTime.now()}!")
|
||||||
updateCourseListRequests()
|
updateCourseListRequests()
|
||||||
return courseList
|
|
||||||
|
return CoursesListRet(courseList.meta, ArrayList(courseList.courses.values))
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/mensamenu")
|
@RequestMapping("/mensamenu")
|
||||||
@ -80,7 +75,7 @@ class APIController {
|
|||||||
|
|
||||||
@RequestMapping("/timetable")
|
@RequestMapping("/timetable")
|
||||||
fun timetable(
|
fun timetable(
|
||||||
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
|
@RequestParam(value = "course", defaultValue = "AI4") courseName: String,
|
||||||
@RequestParam(value = "week", defaultValue = "0") week: Int
|
@RequestParam(value = "week", defaultValue = "0") week: Int
|
||||||
): TimetableCourseWeek {
|
): TimetableCourseWeek {
|
||||||
logger.info("timetable request at ${LocalDateTime.now()}!")
|
logger.info("timetable request at ${LocalDateTime.now()}!")
|
||||||
@ -88,20 +83,20 @@ class APIController {
|
|||||||
return getTimetable(courseName, week)
|
return getTimetable(courseName, week)
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/lessonSubjectList")
|
@RequestMapping("/subjectList")
|
||||||
fun lessonSubjectList(
|
fun lessonSubjectList(
|
||||||
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
|
@RequestParam(value = "course", defaultValue = "AI4") courseName: String,
|
||||||
@RequestParam(value = "week", defaultValue = "0") week: Int
|
@RequestParam(value = "week", defaultValue = "0") week: Int
|
||||||
): HashSet<String> {
|
): HashSet<String> {
|
||||||
logger.info("lessonSubjectList request at ${LocalDateTime.now()}!")
|
logger.info("subjectList request at ${LocalDateTime.now()}!")
|
||||||
updateTimetableRequests(courseName)
|
updateTimetableRequests(courseName)
|
||||||
return getLessonSubjectList(courseName, week)
|
return getLessonSubjectList(courseName, week)
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/lessons")
|
@RequestMapping("/lessons")
|
||||||
fun lesson(
|
fun lesson(
|
||||||
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
|
@RequestParam(value = "course", defaultValue = "AI4") courseName: String,
|
||||||
@RequestParam(value = "lessonSubject", defaultValue = "Mathematik 4") lessonSubject: String,
|
@RequestParam(value = "subject", defaultValue = "Mathematik 4") lessonSubject: String,
|
||||||
@RequestParam(value = "week", defaultValue = "0") week: Int
|
@RequestParam(value = "week", defaultValue = "0") week: Int
|
||||||
): ArrayList<Lesson> {
|
): ArrayList<Lesson> {
|
||||||
logger.info("lesson request at ${LocalDateTime.now()}!")
|
logger.info("lesson request at ${LocalDateTime.now()}!")
|
||||||
@ -121,4 +116,25 @@ class APIController {
|
|||||||
return 200
|
return 200
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deprecated section
|
||||||
|
*/
|
||||||
|
|
||||||
|
// TODO remove this with API version 2.0.0
|
||||||
|
@Deprecated("courses is replaced by courseList", replaceWith = ReplaceWith("courseList()"))
|
||||||
|
@RequestMapping("/courses")
|
||||||
|
fun courses(): CoursesListRet {
|
||||||
|
return courseList()
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO remove this with API version 2.0.0
|
||||||
|
@Deprecated("the parameter courseName is deprecated please use course", ReplaceWith("timetable(courseName, week)"))
|
||||||
|
@RequestMapping("/timetable", params= ["courseName", "week"])
|
||||||
|
fun timetableDep(
|
||||||
|
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
|
||||||
|
@RequestParam(value = "week", defaultValue = "0") week: Int
|
||||||
|
): TimetableCourseWeek {
|
||||||
|
return timetable(courseName, week)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -24,13 +24,15 @@ package org.mosad.thecitadelofricks
|
|||||||
|
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.collections.HashMap
|
||||||
|
|
||||||
// data classes for the course part
|
// data classes for the course part
|
||||||
data class Course(val courseName: String, val courseLink: String)
|
data class Course(val courseName: String, val courseLink: String)
|
||||||
|
|
||||||
data class CoursesMeta(val updateTime: Long, val totalCourses: Int)
|
data class CoursesMeta(val updateTime: Long = 0, val totalCourses: Int = 0)
|
||||||
|
|
||||||
data class CoursesList(val meta: CoursesMeta, val courses: ArrayList<Course>)
|
data class CoursesList(val meta: CoursesMeta = CoursesMeta(), val courses: SortedMap<String, Course>)
|
||||||
|
data class CoursesListRet(val meta: CoursesMeta = CoursesMeta(), val courses: ArrayList<Course> = ArrayList())
|
||||||
|
|
||||||
// data classes for the Mensa part
|
// data classes for the Mensa part
|
||||||
data class Meal(val day: String, val heading: String, val parts: ArrayList<String>, val additives: String)
|
data class Meal(val day: String, val heading: String, val parts: ArrayList<String>, val additives: String)
|
||||||
@ -62,7 +64,6 @@ data class TimetableCourseWeek(val meta: TimetableCourseMeta = TimetableCourseMe
|
|||||||
|
|
||||||
|
|
||||||
// data classes for the status part
|
// data classes for the status part
|
||||||
data class TimetableCounter(var courseName: String, var requests: Int)
|
|
||||||
|
|
||||||
data class Status(
|
data class Status(
|
||||||
val time: LocalDateTime,
|
val time: LocalDateTime,
|
||||||
@ -72,7 +73,7 @@ data class Status(
|
|||||||
val totalRequests: Int,
|
val totalRequests: Int,
|
||||||
val mensaMenuRequests: Int,
|
val mensaMenuRequests: Int,
|
||||||
val courseListRequests: Int,
|
val courseListRequests: Int,
|
||||||
val timetableRequests: ArrayList<TimetableCounter>,
|
val timetableRequests: HashMap<String, Int>,
|
||||||
val timetableListSize: Int,
|
val timetableListSize: Int,
|
||||||
val coursesLastUpdate: Date,
|
val coursesLastUpdate: Date,
|
||||||
val mensaLastUpdate: Date,
|
val mensaLastUpdate: Date,
|
||||||
|
@ -23,22 +23,19 @@
|
|||||||
package org.mosad.thecitadelofricks.controller
|
package org.mosad.thecitadelofricks.controller
|
||||||
|
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.async
|
import org.jsoup.Jsoup
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.mosad.thecitadelofricks.*
|
import org.mosad.thecitadelofricks.*
|
||||||
import org.mosad.thecitadelofricks.hsoparser.CourseListParser
|
import org.mosad.thecitadelofricks.hsoparser.CourseListParser
|
||||||
import org.mosad.thecitadelofricks.hsoparser.MensaParser
|
import org.mosad.thecitadelofricks.hsoparser.MensaParser
|
||||||
import org.mosad.thecitadelofricks.hsoparser.TimetableParser
|
import org.mosad.thecitadelofricks.hsoparser.TimetableParser
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.io.BufferedWriter
|
import java.io.*
|
||||||
import java.io.File
|
|
||||||
import java.io.FileWriter
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
import kotlin.collections.HashMap
|
||||||
import kotlin.collections.HashSet
|
import kotlin.collections.HashSet
|
||||||
import kotlin.concurrent.scheduleAtFixedRate
|
import kotlin.concurrent.scheduleAtFixedRate
|
||||||
|
|
||||||
@ -52,9 +49,9 @@ class CacheController {
|
|||||||
companion object{
|
companion object{
|
||||||
private val logger: Logger = LoggerFactory.getLogger(CacheController::class.java)
|
private val logger: Logger = LoggerFactory.getLogger(CacheController::class.java)
|
||||||
|
|
||||||
var courseList = CoursesList(CoursesMeta(0, 0), ArrayList())
|
var courseList = CoursesList(CoursesMeta(), sortedMapOf())
|
||||||
var mensaMenu = MensaMenu(MensaMeta(0,""), MensaWeek(), MensaWeek())
|
var mensaMenu = MensaMenu(MensaMeta(0,""), MensaWeek(), MensaWeek())
|
||||||
var timetableList = ArrayList<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
|
* get a timetable, since they may not be cached, we need to make sure it's cached, otherwise download
|
||||||
@ -63,30 +60,36 @@ class CacheController {
|
|||||||
* @return timetable of the course (Type: [TimetableCourseWeek])
|
* @return timetable of the course (Type: [TimetableCourseWeek])
|
||||||
*/
|
*/
|
||||||
fun getTimetable(courseName: String, weekIndex: Int): TimetableCourseWeek = runBlocking {
|
fun getTimetable(courseName: String, weekIndex: Int): TimetableCourseWeek = runBlocking {
|
||||||
val currentTime = System.currentTimeMillis() / 1000
|
|
||||||
var timetable = TimetableWeek()
|
|
||||||
var weekNumberYear = 0
|
|
||||||
|
|
||||||
// check if the timetable already exists and is up to date
|
// TODO just for testing
|
||||||
when (timetableList.stream().filter { x -> x.meta.courseName == courseName && x.meta.weekIndex == weekIndex }.findAny().orElse(null)) {
|
if (courseName == "TEST_A" || courseName == "TEST_B") {
|
||||||
// there is no such course yet, create one
|
val currentTime = System.currentTimeMillis() / 1000
|
||||||
null -> {
|
val timetableLink = "https://mosad.xyz"
|
||||||
val courseLink = courseList.courses.stream().filter { x -> x.courseName == courseName }.findFirst().orElse(null).courseLink
|
val weekNumberYear = 0
|
||||||
val timetableLink = courseLink.replace("week=0","week=$weekIndex")
|
val instr = javaClass.getResourceAsStream("/html/Timetable_normal-week.html")
|
||||||
|
|
||||||
val jobTimetable = async {
|
val htmlDoc = Jsoup.parse(instr,"UTF-8", "https://www.hs-offenburg.de/")
|
||||||
timetable = TimetableParser().getTimeTable(timetableLink)
|
val timetableTest = TimetableParser().parseTimeTable(htmlDoc)
|
||||||
weekNumberYear = TimetableParser().getWeekNumberYear(timetableLink)
|
|
||||||
}
|
|
||||||
|
|
||||||
jobTimetable.await()
|
return@runBlocking TimetableCourseWeek(TimetableCourseMeta(currentTime, courseName, weekIndex, weekNumberYear, timetableLink), timetableTest)
|
||||||
timetableList.add(TimetableCourseWeek(TimetableCourseMeta(currentTime, courseName, weekIndex, weekNumberYear, timetableLink), timetable))
|
|
||||||
|
|
||||||
logger.info("added new timetable for $courseName, week $weekIndex")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return@runBlocking timetableList.stream().filter { x -> x.meta.courseName == courseName && x.meta.weekIndex == weekIndex }.findAny().orElse(null)
|
return@runBlocking timetableList.getOrPut("$courseName-$weekIndex") {
|
||||||
|
val timetableLink = courseList.courses[courseName]
|
||||||
|
?.courseLink
|
||||||
|
?.replace("week=0", "week=$weekIndex") ?: ""
|
||||||
|
val currentTime = System.currentTimeMillis() / 1000
|
||||||
|
var timetable = TimetableWeek()
|
||||||
|
var weekNumberYear = 0
|
||||||
|
|
||||||
|
val timetableJobs = listOf(
|
||||||
|
async { timetable = TimetableParser().getTimeTable(timetableLink) },
|
||||||
|
async { weekNumberYear = TimetableParser().getWeekNumberYear(timetableLink) }
|
||||||
|
)
|
||||||
|
|
||||||
|
timetableJobs.awaitAll()
|
||||||
|
TimetableCourseWeek(TimetableCourseMeta(currentTime, courseName, weekIndex, weekNumberYear, timetableLink), timetable)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,9 +137,13 @@ class CacheController {
|
|||||||
*/
|
*/
|
||||||
private fun asyncUpdateCourseList() = GlobalScope.launch {
|
private fun asyncUpdateCourseList() = GlobalScope.launch {
|
||||||
CourseListParser().getCourseLinks(StartupController.courseListURL)?.let {
|
CourseListParser().getCourseLinks(StartupController.courseListURL)?.let {
|
||||||
courseList = CoursesList(CoursesMeta(System.currentTimeMillis() / 1000, it.size), it)
|
courseList = CoursesList(CoursesMeta(System.currentTimeMillis() / 1000, it.size), it.toSortedMap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO just for testing
|
||||||
|
courseList.courses["TEST_A"] = Course("TEST_A", "https://mosad.xyz")
|
||||||
|
courseList.courses["TEST_B"] = Course("TEST_B", "https://mosad.xyz")
|
||||||
|
|
||||||
logger.info("Updated courses successful at ${Date(courseList.meta.updateTime * 1000)}")
|
logger.info("Updated courses successful at ${Date(courseList.meta.updateTime * 1000)}")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,10 +177,10 @@ class CacheController {
|
|||||||
try {
|
try {
|
||||||
timetableList.forEach { timetableCourse ->
|
timetableList.forEach { timetableCourse ->
|
||||||
executor.execute {
|
executor.execute {
|
||||||
timetableCourse.timetable = TimetableParser().getTimeTable(timetableCourse.meta.link)
|
timetableCourse.value.timetable = TimetableParser().getTimeTable(timetableCourse.value.meta.link)
|
||||||
timetableCourse.meta.updateTime = System.currentTimeMillis() / 1000
|
timetableCourse.value.meta.updateTime = System.currentTimeMillis() / 1000
|
||||||
|
|
||||||
saveTimetableToCache(timetableCourse) // save the updated timetable to the cache directory
|
saveTimetableToCache(timetableCourse.value) // save the updated timetable to the cache directory
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -190,12 +197,16 @@ class CacheController {
|
|||||||
* @param timetable a timetable of the type [TimetableCourseWeek]
|
* @param timetable a timetable of the type [TimetableCourseWeek]
|
||||||
*/
|
*/
|
||||||
private fun saveTimetableToCache(timetable: TimetableCourseWeek) {
|
private fun saveTimetableToCache(timetable: TimetableCourseWeek) {
|
||||||
println(timetable.timetable.toString())
|
|
||||||
|
|
||||||
val file = File(StartupController.dirTcorCache, "timetable-${timetable.meta.courseName}-${timetable.meta.weekIndex}.json")
|
val file = File(StartupController.dirTcorCache, "timetable-${timetable.meta.courseName}-${timetable.meta.weekIndex}.json")
|
||||||
val writer = BufferedWriter(FileWriter(file))
|
val writer = BufferedWriter(FileWriter(file))
|
||||||
writer.write(Gson().toJson(timetable))
|
|
||||||
writer.close()
|
try {
|
||||||
|
writer.write(Gson().toJson(timetable))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logger.error("something went wrong while trying to write a cache file", e)
|
||||||
|
} finally {
|
||||||
|
writer.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,7 +134,8 @@ class StartupController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
val timetableObject = JsonParser.parseString(bufferedReader.readLine()).asJsonObject
|
val timetableObject = JsonParser.parseString(bufferedReader.readLine()).asJsonObject
|
||||||
CacheController.timetableList.add(Gson().fromJson(timetableObject, TimetableCourseWeek().javaClass))
|
val timetable = Gson().fromJson(timetableObject, TimetableCourseWeek().javaClass)
|
||||||
|
CacheController.timetableList.put("${timetable.meta.courseName}-${timetable.meta.weekIndex}", timetable)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
logger.error("error while reading cache", ex)
|
logger.error("error while reading cache", ex)
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -26,14 +26,13 @@ import org.mosad.thecitadelofricks.APIController.Companion.apiVersion
|
|||||||
import org.mosad.thecitadelofricks.APIController.Companion.softwareVersion
|
import org.mosad.thecitadelofricks.APIController.Companion.softwareVersion
|
||||||
import org.mosad.thecitadelofricks.APIController.Companion.startTime
|
import org.mosad.thecitadelofricks.APIController.Companion.startTime
|
||||||
import org.mosad.thecitadelofricks.Status
|
import org.mosad.thecitadelofricks.Status
|
||||||
import org.mosad.thecitadelofricks.TimetableCounter
|
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.HashMap
|
||||||
|
|
||||||
class StatusController {
|
class StatusController {
|
||||||
|
|
||||||
@ -43,7 +42,7 @@ class StatusController {
|
|||||||
private var totalRequests = 0
|
private var totalRequests = 0
|
||||||
private var mensaMenuRequests = 0
|
private var mensaMenuRequests = 0
|
||||||
private var courseListRequests = 0
|
private var courseListRequests = 0
|
||||||
private var timetableRequests = ArrayList<TimetableCounter>()
|
private var timetableRequests = HashMap<String, Int>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if a mensamenu/courseList/timetable is requested update the specific and total request count
|
* if a mensamenu/courseList/timetable is requested update the specific and total request count
|
||||||
@ -59,11 +58,7 @@ class StatusController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateTimetableRequests(courseName: String) {
|
fun updateTimetableRequests(courseName: String) {
|
||||||
timetableRequests.stream().filter { it.courseName == courseName }.findFirst().ifPresentOrElse({
|
timetableRequests[courseName] = timetableRequests.getOrPut(courseName) {0} + 1
|
||||||
it.requests++
|
|
||||||
}, {
|
|
||||||
timetableRequests.add(TimetableCounter(courseName, 1))
|
|
||||||
})
|
|
||||||
totalRequests++
|
totalRequests++
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +77,7 @@ class StatusController {
|
|||||||
return courseListRequests
|
return courseListRequests
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTimetableRequests(): ArrayList<TimetableCounter> {
|
fun getTimetableRequests(): HashMap<String, Int> {
|
||||||
return timetableRequests
|
return timetableRequests
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,26 +29,25 @@ import java.net.SocketTimeoutException
|
|||||||
|
|
||||||
class CourseListParser {
|
class CourseListParser {
|
||||||
|
|
||||||
var logger: org.slf4j.Logger = LoggerFactory.getLogger(MensaParser::class.java)
|
private var logger: org.slf4j.Logger = LoggerFactory.getLogger(CourseListParser::class.java)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return a list of all courses at courseListURL
|
* return a list of all courses at courseListURL
|
||||||
* @param courseListURL the url to the course list page
|
* @param courseListURL the url to the course list page
|
||||||
* @return a ArrayList<Course> with all courses or null if the request was not successful
|
* @return a ArrayList<Course> with all courses or null if the request was not successful
|
||||||
*/
|
*/
|
||||||
fun getCourseLinks(courseListURL: String): ArrayList<Course>? {
|
fun getCourseLinks(courseListURL: String): HashMap<String, Course>? {
|
||||||
val courseLinkList = ArrayList<Course>()
|
val courseLinkList = HashMap<String, Course>()
|
||||||
try {
|
try {
|
||||||
val courseHTML = Jsoup.connect(courseListURL).get()
|
val courseHTML = Jsoup.connect(courseListURL).get()
|
||||||
|
|
||||||
courseHTML.select("ul.index-group").select("li.Class").select("a[href]").forEachIndexed { _, element ->
|
courseHTML.select("ul.index-group").select("li.Class").select("a[href]").forEachIndexed { _, element ->
|
||||||
courseLinkList.add(
|
courseLinkList[element.text()] = Course(
|
||||||
Course(
|
element.text(),
|
||||||
element.text(),
|
element.attr("href").replace("http", "https")
|
||||||
element.attr("href").replace("http", "https")
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
logger.info("successfully retrieved course List")
|
||||||
} catch (ex: SocketTimeoutException) {
|
} catch (ex: SocketTimeoutException) {
|
||||||
logger.warn("timeout from hs-offenburg.de, updating on next attempt!")
|
logger.warn("timeout from hs-offenburg.de, updating on next attempt!")
|
||||||
return null
|
return null
|
||||||
|
@ -181,4 +181,5 @@ class TimetableParser {
|
|||||||
|
|
||||||
println(" \n")
|
println(" \n")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -11,5 +11,5 @@ logging.level.org.springframework.web=INFO
|
|||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
|
|
||||||
# EMBEDDED SERVER CONFIGURATION (ServerProperties)
|
# EMBEDDED SERVER CONFIGURATION (ServerProperties)
|
||||||
server.address=127.0.0.1
|
server.address=0.0.0.0
|
||||||
server.port=8080
|
server.port=8080
|
1726
src/main/resources/html/Timetable_normal-week.html
Normal file
1726
src/main/resources/html/Timetable_normal-week.html
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user