added a configuration via config.xml file
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
* the config file contains the Mensa name and URL, the Cachet Base-URL and API-Key
This commit is contained in:
@ -42,11 +42,6 @@ class CacheController {
|
||||
|
||||
private val logger: Logger = LoggerFactory.getLogger(CacheController::class.java)
|
||||
|
||||
// hso parser links (hardcoded)
|
||||
private val courseListURL = "https://www.hs-offenburg.de/studium/vorlesungsplaene/"
|
||||
private val mensaMenuURL = "https://www.swfr.de/de/essen-trinken/speiseplaene/mensa-offenburg/"
|
||||
private val mensaName = "Offenburg"
|
||||
|
||||
init {
|
||||
initUpdates()
|
||||
scheduledUpdates()
|
||||
@ -154,7 +149,7 @@ class CacheController {
|
||||
* during the update process the old data will be returned for a API request
|
||||
*/
|
||||
private fun asyncUpdateCourseList() = GlobalScope.launch {
|
||||
CourseListParser().getCourseLinks(courseListURL)?.let {
|
||||
CourseListParser().getCourseLinks(StartupController.getCourseListURL())?.let {
|
||||
courseList = CourseList(
|
||||
CourseMeta(System.currentTimeMillis() / 1000, it.size), it
|
||||
)
|
||||
@ -168,13 +163,13 @@ class CacheController {
|
||||
* during the update process the old data will be returned for a API request
|
||||
*/
|
||||
private fun asyncUpdateMensa() = GlobalScope.launch {
|
||||
val mensaCurrentWeek = MensaParser().getMensaMenu(mensaMenuURL)
|
||||
val mensaNextWeek = MensaParser().getMensaMenu(MensaParser().getMenuLinkNextWeek(mensaMenuURL))
|
||||
val mensaCurrentWeek = MensaParser().getMensaMenu(StartupController.getMensaMenuURL())
|
||||
val mensaNextWeek = MensaParser().getMensaMenu(MensaParser().getMenuLinkNextWeek(StartupController.getMensaMenuURL()))
|
||||
|
||||
// only update if we get valid data
|
||||
if (mensaCurrentWeek != null && mensaNextWeek != null) {
|
||||
mensaMenu = MensaMenu(
|
||||
MensaMeta(System.currentTimeMillis() / 1000, mensaName), mensaCurrentWeek, mensaNextWeek
|
||||
MensaMeta(System.currentTimeMillis() / 1000, StartupController.getMensaName()), mensaCurrentWeek, mensaNextWeek
|
||||
)
|
||||
}
|
||||
|
||||
@ -214,7 +209,7 @@ class CacheController {
|
||||
private fun initUpdates() = runBlocking {
|
||||
// get all courses on startup
|
||||
val jobCourseUpdate = GlobalScope.async {
|
||||
CourseListParser().getCourseLinks(courseListURL)?.let {
|
||||
CourseListParser().getCourseLinks(StartupController.getCourseListURL())?.let {
|
||||
courseList = CourseList(
|
||||
CourseMeta(System.currentTimeMillis() / 1000, it.size), it
|
||||
)
|
||||
@ -223,13 +218,13 @@ class CacheController {
|
||||
|
||||
// get the current and next weeks mensa menus
|
||||
val jobMensa = GlobalScope.async{
|
||||
val mensaCurrentWeek = MensaParser().getMensaMenu(mensaMenuURL)
|
||||
val mensaNextWeek = MensaParser().getMensaMenu(MensaParser().getMenuLinkNextWeek(mensaMenuURL))
|
||||
val mensaCurrentWeek = MensaParser().getMensaMenu(StartupController.getMensaMenuURL())
|
||||
val mensaNextWeek = MensaParser().getMensaMenu(MensaParser().getMenuLinkNextWeek(StartupController.getMensaMenuURL()))
|
||||
|
||||
// only update if we get valid data
|
||||
if (mensaCurrentWeek != null && mensaNextWeek != null) {
|
||||
mensaMenu = MensaMenu(
|
||||
MensaMeta(System.currentTimeMillis() / 1000, mensaName), mensaCurrentWeek, mensaNextWeek
|
||||
MensaMeta(System.currentTimeMillis() / 1000, StartupController.getMensaName()), mensaCurrentWeek, mensaNextWeek
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -265,9 +260,11 @@ class CacheController {
|
||||
asyncUpdateMensa()
|
||||
}
|
||||
|
||||
// post to status.mosad.xyz every hour
|
||||
Timer().scheduleAtFixedRate(initDelay1h, 3600000) {
|
||||
CachetAPIController.postTotalRequests()
|
||||
// post to status.mosad.xyz every hour, if an API key is present
|
||||
if (StartupController.getCachetAPIKey() != "0") {
|
||||
Timer().scheduleAtFixedRate(initDelay1h, 3600000) {
|
||||
CachetAPIController.postTotalRequests()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user